On 5/17/07, Ben Jones <[EMAIL PROTECTED]> wrote:
>
> I have 2 models that I'm using "for training": Content and Category
> with a ManyToMany field in Content to relate them.
>
> For test data, I have entered 3 categories and 3 pieces of content
> (one in each of the 3 categories).

You have 3 categories and 3 content objects, but what is in the m2m
table between them? What is the matrix of category/content
relationships?

> In my understanding of the docs, I expected to be able to use the line
> of code below to retrieve all pieces of content in the category with a
> slug of 'list-1'. However, that appears to not be the case, as every
> record from Content is returned.
>
> >>> Content.objects.filter(categories__slug__exact = 'list-1')
> [<Content: Piece 1>, <Content: Piece 2>, <Content: Da 3rd>]

The syntax appears right for the problem you are describing;

> Should I expect these to be the same (in which case I'm doing
> something wrong)

They will only be the same if the m2m relations between the objects
are correct. At is, it looks like all three content objects are
related to the first category.

> or does the section in the docs here ("Lookups that
> span relationships") . . .
>
> http://www.djangoproject.com/documentation/db-api/#lookups-that-span-relationships
>
> . . . only apply to One-to-many relationships?

No - they apply to both. The query language makes no distinction
between M2M and M2O relations.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to