On Thursday, 12 April 2012 at 10:47 PM, Andre Terra wrote:
> On Thu, Apr 12, 2012 at 10:01 AM, David <cthl...@gmail.com > (mailto:cthl...@gmail.com)> wrote: > > Log.objects.distinct('thing__id').order_by('thing__id', > > '-modified_on').select_related().filter(thing__deleted=0)[:20] > > > > By avoiding the use of values() I was able to then use the result as an > > object and access everything I needed. > > > > The above ORM statement however does not look as elegant to read as I have > > come to expect from Django though. The resulting SQL doesn't seem too > > shabby however. > > > Django has a tendency of making you write really long lines, but I guess you > could break it into smaller chunks to improve readability. > > logs = Log.objects.distinct('thing__id').order_by('thing__id', > '-modified_on') > related = logs.select_related().filter(thing__deleted=0)[:20] The other option is to find ways to break the line using Python's own syntax. e.g.: Log.objects.distinct( 'thing__id' ).order_by( 'thing__id', '-modified_on' ).select_related( ).filter( thing__deleted=0 )[:20] Yours, Russ Magee %-) -- 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.