If your django queries is too long (>100 character), you can try this style
person = (
models
.UzbekistaniCitizen
.objects
.filter(occupation__income__taxable__gte=40000)
.exclude(face__eyes__color=blue)
.order_by('height')
.select_related('siblings', 'children'))
In this style, the most convenience is you do not have to indent by hand,
every line indent is several 4 spaces.
Disadvantage of the below: 1. If you rename the variable person, you have
to adjust indent by hand. 2. If your model name is very long, it is
difficult to limit every line less than 80 characters.
person = UzbekistaniCitizen.objects.myfilter(hair__color=brown,
eye__color= blue,
height__gt= 56,
...
...
)
My style have other convenience:
1.can add comment:
person = (
models
.UzbekistaniCitizen
.objects
.filter(occupation__income__taxable__gte=40000) # your comment
.exclude(face__eyes__color=blue)
.order_by('height') # 2016-10-11 add
.select_related('siblings', 'children'))
2.easy debug, you can comment some conditions easily
Below code can work fine. This is very useful in debug, you can comment
condition line-by-line, rather than delete it and redo it.
person = (
models
.UzbekistaniCitizen
.objects
# .filter(occupation__income__taxable__gte=40000)
.exclude(face__eyes__color=blue)
# .order_by('height')
.select_related('siblings', 'children'))
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/71d04bb1-cc3f-41d8-b34a-925219a03da6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.