i have a datetime field which can be null and id like to do qs.order_by('field__isnull', 'name') but this results in:
Join on field 'field' not permitted. Did you misspell 'isnull' for the lookup type?
Is this possible at all?
there may be better ways, but one possibility is to annotate your queryset:
from django.db.models import Count
qs.annotate(null_count=Count('field_name')).order_by('null_count')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With