5
我有可能为空,ID喜欢做qs.order_by(“field__isnull”,“名”)时间字段,但是这会导致:django通过isnull值排序?
Join on field 'field' not permitted. Did you misspell 'isnull' for the lookup type?
这是可能的呢?
我有可能为空,ID喜欢做qs.order_by(“field__isnull”,“名”)时间字段,但是这会导致:django通过isnull值排序?
Join on field 'field' not permitted. Did you misspell 'isnull' for the lookup type?
这是可能的呢?
可能有更好的方法,但是一种可能性是注释您的查询集:
from django.db.models import Count
qs.annotate(null_count=Count('field_name')).order_by('null_count')
我希望你的模型是这样的:
date_deleted = models.DateTimeField(blank=True, null=True)
如果真 那么你可以这样做:
qs.order_by('-date_deleted')
这强制按日期排序非空值,而不是asker只想要2组,null和非null。 – Rebs 2014-10-02 07:04:47