VO类应该包含域逻辑吗?(Should VO classes contains the domain logic?)
我一直在阅读这个关于DAO和VO类的网站,以便与PHP和MVC一起使用。 http://www.sitecrafting.com/blog/php-patterns-part-ii/
我想知道应该在哪里放置域逻辑。 (仅处理对象数据,算法等的方法)
它应该在VO课程吗? 或者我应该为域逻辑类创建另一个包?
它与DB无关,所以我认为它不会放在DAO类上。 谢谢。
I have been reading this site about the DAO and VO classes to work with PHP and MVC. http://www.sitecrafting.com/blog/php-patterns-part-ii/
And i was wondering where should it be placed the domain logic. (methods to deal only with the object data, algoritms etc.)
Should it be at the VO classes? Or i should create another package for the domain logic classes?
It is not related with the DB so i assume it won't be placed on the DAO classes. Thanks.
原文:https://stackoverflow.com/questions/11578112
最满意答案
使用\来逃避'char
Operation.objects.exclude(field__icontains="\'foobar\'")
在python中:
>>> a = "\'hi\'" >>> print a 'hi'
use the \ to escape the ' char
Operation.objects.exclude(field__icontains="\'foobar\'")
in python:
>>> a = "\'hi\'" >>> print a 'hi'
相关问答
更多-
你可以使用__in : A.objects.filter(b__in=bs) 或者你可以避免创建bs查询集,并直接在你的查询中关联关系: A.objects.filter(b__bcondition=bvalue) You can use __in: A.objects.filter(b__in=bs) or you can avoid creating the bs queryset at all, and follow the relation directly in your query: A. ...
-
Django全局查询集(Django global queryset)[2022-05-08]
不要在全局范围内初始化查询。 将None绑定到名称,然后编写一个函数,首先检查值是否为None ,如果是,则生成数据,然后返回值。 Don't initialize queries in a global scope. Bind None to the name, then write a function that first checks if the value is None and if so generates the data, and then returns the value. -
此票证讨论了此行为: https : //code.djangoproject.com/ticket/9006 只需使用order_by查询。 发生这种情况是因为如果您未指定显式排序,则数据库引擎可以自由返回任何合适的行。 所以我猜它只是从它的缓存中选择一个。 This ticket discusses this behavior: https://code.djangoproject.com/ticket/9006 Just use order_by query. This happens because ...
-
包含另一个查询集的Model方法的Django查询集(Django queryset with Model method containing another queryset)[2021-11-29]
不确定这是否是最好的方法,但它确实有效。 如果有人发布了更好的答案,我会接受他们的。 class OtherModel(models.Model) ... class MyModelManager(models.Manager): def get_queryset(self): self.model.list_other_model = OtherModel.objects.all() return super(MyModelManager, self).g ... -
这种事情非常棘手。 我实际上会在视图中完成所有工作,在那里修改查询集并将其传递给模板。 rank = 1 previous = None entries = list(entries) previous = entries[0] previous.rank = 1 for i, entry in enumerate(entries[1:]): if entry.value != previous.value: rank = i + 2 entry.rank = str ...
-
编辑您的ContactForm class ContactForm(ModelForm): contatto_choice = forms.ModelChoiceField(queryset=Choice.objects.all()) class Meta: model = Contatto fields = ['contatto_choice', 'phone_number','email','text'] 你不需要其他形式 Edit Your C ...
-
您的问题实际上并不清楚您的实际期望,但无论如何,这里有一些提示: 首先,模型实例(假设它们是相同模型的实例)比较它们的主键值,该键值也用作字典和集合的哈希值,因此如果要比较基础数据库记录,则不应使用模型实例,但将原始数据库值视为元组或列表的列表。 您可以使用(或) Queryset.values_list()或Queryset.values()来获得这些内容 - 不要忘记list()它们,以便您真正获得list而不是查询集。 这将我们带到了第二个重要的地方:虽然将自己呈现为列表类(在它们支持len() ,迭 ...
-
Django查询集幕后(Django queryset behind the scenes)[2023-06-09]
如果执行以下命令,将揭示神秘感 ./manage.py sqlmigrate myapp 0001 请注意使用您的应用名称(我认为是bfm )替换myapp ,并使用创建Comment模型的实际迁移替换0001。 生成的sql将显示实际表是使用place_id int而不是place Place创建的,因为RDBMS对模型一无所知,模型只在应用程序级别。 django orm的工作是从RDBMS获取数据并将它们转换为模型实例。 这就是为什么你总是在每个Comment实例中获得一个place成员,并且该pl ... -
使用\来逃避'char Operation.objects.exclude(field__icontains="\'foobar\'") 在python中: >>> a = "\'hi\'" >>> print a 'hi' use the \ to escape the ' char Operation.objects.exclude(field__icontains="\'foobar\'") in python: >>> a = "\'hi\'" >>> print a 'hi'
-
查询集中没有高级group_by 。 它用于aggregate和annotate调用,但它不适用于您。 有一个低级API,根本没有记录。 您可以获得内部查询说明: queryset = ... #whatever query you'd want to group by query = queryset.query 然后你可以通过添加一个你想要分组的字段来改变group_by成员 - 这是一个列表: query.group_by.append('a_field') 但: 你必须认真地知道你在做什么。 这 ...