Thanks! This is a great starting point. My real queryset requires me
to go a few joins deeper, however. I will try nesting loops to get
there, but this seems frightfully like querying in a loop (maybe I'm
wrong, I'll check the end query to find out). It also seems like a
frightening amount of code to write to to produce a query which
ultimately looks like this in SQL...
# SELECT containers.* FROM containers\
# INNER JOIN containers_and_categories ON\
# containers.id = containers_and_categories.container_id\
# INNER JOIN flattened_category ON\
# containers_and_categories.category_id =
flattened_category.member_of_category_id\
# WHERE flattened_category.member_of_category_id = %s",
[request.POST["cat-id"]])
I'm pondering switching to
http://blog.doughellmann.com/2007/12/using-raw-sql-in-django.html
for much of my querying (other than very basic joins, which work well
in django)
On May 6, 2:46 pm, Alex Koshelev <[email protected]> wrote:
> On Wed, May 6, 2009 at 8:48 PM, jrs_66 <[email protected]> wrote:
>
> > Hi,
>
> > I have 2 models...
>
> [skip]
>
> > e = FlattenedCategory.objects.select_related('category').filter
> > (member_of_category=15)
>
> > which works... This, however, doesn't....
>
> > e = e.category
>
> > How do I access the related records from the Category model?
>
> This this QuerySet it is simple:
>
> categories = [fcategory.category for fcategory in e]
>
> or fetch only categories right away:
>
> categories =
> Category.objects.filter(flattenedcategory__member_of_category=15).distinct()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---