Hi guys, I've been trying your suggestions but I'm afraid I'm stretching the limits of my Python/Django abilities ;-)
Bruno got it right: what I want is a queryset of "model" with distinct docid having the highest version number, sorted by revisiondate. If have the following result of my found_entries = model.objects.filter((Q- objects),obsolete=0).order_by('-version','docid') : +----+-------+---------+--------------+ | pk | docid | version | revisiondate | +----+-------+---------+--------------+ | 1 | 1 | 1 | 2000-02-10 | | 2 | 2 | 1 | 2000-02-11 | | 3 | 3 | 1 | 2000-02-12 | | 4 | 3 | 3 | 2000-02-13 | | 5 | 2 | 3 | 2000-02-14 | | 6 | 1 | 3 | 2000-02-15 | +----+-------+---------+--------------+ Then I want to retrieve only these results, sorted on revisiondate: +----+-------+---------+--------------+ | pk | docid | version | revisiondate | +----+-------+---------+--------------+ | 6 | 1 | 3 | 2000-02-15 | | 5 | 2 | 3 | 2000-02-14 | | 4 | 3 | 3 | 2000-02-13 | +----+-------+---------+--------------+ My code does this, but the loop that selects the distinct docid's is what makes it terribly slow... Hope this clarifies it. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.