Re: Django query not returning all objects

2016-08-19 Thread Constantine Covtushenko
Hi Koonal, Sorry for not exact suggestion. I hope that combination of `annotate` and `values` will be helpful, see this link for more detailed explanation . Pleas try something like following: cases = HeartFlowCase.objects.v

Re: Django query not returning all objects

2016-08-19 Thread Simon Charette
For reference there's a Django ticket to suggest using this technique. Cheers, Simon [1] https://code.djangoproject.com/ticket/19842 Le jeudi 18 août 2016 02:20:34 UTC-4, Todor Velichkov a écrit : > > Another solution would be to annotate min/max deadline date and order by > the annotation. Som

Re: Django query not returning all objects

2016-08-18 Thread Koonal Bharadwaj
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 applyi

Re: Django query not returning all objects

2016-08-18 Thread Koonal Bharadwaj
Hi Constantine, Thanks for the quick reply. No luck with distinct. I tried that before (cases = cases.distinct() ), right after the order_by but it seems to have no effect, returning multiple duplicates. On Wednesday, August 17, 2016 at 9:59:19 PM UTC-7, Constantine Covtushenko wrote: > > H

Re: Django query not returning all objects

2016-08-17 Thread Todor Velichkov
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') On Thursday, August 18, 2016 at 7:59:19 AM UTC+3, Constantine Covtushenko wrote: >

Re: Django query not returning all objects

2016-08-17 Thread Constantine Covtushenko
Hi Koonal, As said in django doc you can use `distinct()` to remove duplicated rows from first query. I believe with this your pagination should works as expected. Regards, On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj

Django query not returning all objects

2016-08-17 Thread Koonal Bharadwaj
Hello, The issue: When trying to order_by on a related model duplicate entries are created. I solved this with an OrderedSet that is applied after paginating ( http://code.activestate.com/recipes/576694/). However, when I try to paginate the queryset, all the results are not returned. It's miss