Hi Todor, I have implemented something similar:
cases = HeartFlowCase.objects.all().annotate(Count('hf_id', distinct=True)) I also tried your suggestion and both seem to produce the same results. The number of duplicates is minimized but not removed entirely. Also the same problem when applying it to pagination still persists. Thanks for the suggestion. On Wednesday, August 17, 2016 at 11:20:34 PM UTC-7, Todor Velichkov wrote: > > Another solution would be to annotate min/max deadline date and order by > the annotation. Something like: > > cases = HeartFlowCase.objects.all().annotate(min_deadline=Min( > 'data__deadline')).order_by('min_deadline') > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5a4937c7-72f8-4e1e-844a-6ae607abbc61%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.