On Oct 19, 4:17 pm, Tomasz Zieliński
<tomasz.zielin...@pyconsultant.eu> wrote:
> Say I have Object model, which has ObjectRevision-s (ObjectRevision
> has ForeignKey to Object). I want to fetch from database all latest
> ObjectRevision-s. In SQL I can do it like this:
>
> SELECT r1.some_data
> FROM objectrevision r1
> LEFT OUTER JOIN objectrevision nr2
> ON (r1.object_id = r2.object_id AND r1.id < r2.id)
> WHERE r2.id IS NULL
>
> What would be be the best way to do it with Django ORM?
>

It's not clear what you mean by 'all latest ObjectRevisions'. Do you
mean all ObjectRevisions for a particular object? If so:
    myobject.objectrevision_set.all()
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to