我一直在这样做:
Model.objects.filter(key1=value1)\
.exclude(key2=value2)\
.order_by('key3')\
.select_related(depth=1)
但我讨厌
\
。有没有更清洁的风格? 最佳答案
或者,您可以利用Django QuerySet操作是累积的和惰性的这一事实:
myobjects = Model.objects.filter(key1=value1)
myobjects = myobjects.exclude(key2=value2)
myobjects = myobjects.order_by('key3')
myobjects = myobjects.select_related(depth=1)