--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Thanks again
Well, after good night sleep I've some idea.
Something like should do the trick:
Log.objects.values('thing').annotate(deletion_date=Max('modified_on')).order_by('-deletion_date')
--
Jani Tiainen
Hi JaniThat was very helpful. Is there a way to include select_related into that query? or do I have to list every single field I would like to return using values()?last_deleted = ModificationLog.objects.values('thing__id', ' thing__prefix', ' thing __first_name', ' thing__last_name', ' thing__company_name', 'thing__creator', ' thing __created_on', 'modifier').annotate(deletion_date=Max('modified_on')).filter(thing__deleted=1).order_by('-deletion_date')[:20]This for example works, but I don't have access to User. Thing contains a FK to the User model, but I'm unable to do in the template {{ object_list.creator.get_full_name }}
But I am a lot lot closer than I was before, thank you.
I suppose that you have to add all fields. I suggest that you install
django-command-extensions and IPython. Run ./manage.py shell_plus and
start experimenting.
--
Jani Tiainen
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.
On Thursday, 12 April 2012 at 10:47 PM, Andre Terra wrote:
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 %-)