2009/10/19 Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>

>
> On 19 Paź, 20:21, Daniel Roseman <dan...@roseman.org.uk> wrote:
> >
> > You can't do this in one query with Django's ORM.
> >
> > One way of doing it in two queries might be to get use .annotate() to
> > add the max id of the related objectrevision for each revision, then
> > get all those objectrevisions (untested):
> >
> >    objects = Object.objects.all().annotate(revision_id=Max
> > ('objectrevision__id'))
> >    objectrevisions = ObjectRevision.objects.filter(id__in=
> > [o.revision_id for o in objects])
> >
>
> I found this solution, but we are talking about thousends of objects,
> so SQL query would be really huge. I' tested it with MySQL Query
> Browser
> and passing ton of ids to `WHERE id IN (...)` clause was causing major
> overhead
> comparing to using JOIN.
>
> Fortunately, in the mean time, I've found a nice solution using SQL
> views:
>
>
> http://wolfram.kriesing.de/blog/index.php/2007/django-nice-and-critical-article#comment-48425
>
> This is not strictly a solution to the problem I asked, but it allows
> to hide SQL under the floor
> and just use Django ORM in everydays work.
>
> Anyway, thank you for confirmation on this limitation, I wasn't sure
> about it.
>

Interesting. I've been wondering how one might tackle accessing views via
models. Thanks for the link.

--~--~---------~--~----~------------~-------~--~----~
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