Thanks!
I'll use the intermediary model for my solution.

Best Regards,

Jeff Anderson

Malcolm Tredinnick wrote:
> On Thu, 2007-12-20 at 22:23 -0700, Jeff Anderson wrote:
>   
>> I am used to designing relational databases, and I love django's
>> capabilities with the models and its database APIs.
>>
>> I have an app with the following models:
>>
>> Room
>> Furniture
>>
>> Room will store records like: "living room", "family room", "kitchen",
>> etc...
>> Furniture will store records like: "chair", "table", "rug", etc...
>>
>> Each room can have a chair in it, and a chair may be in multiple rooms.
>> My first thought was to use a many to many model. This would be fine,
>> until I wanted to keep a count of each type of furniture. The kitchen
>> has 4 chairs, the living room has 2.
>>
>> In a regular relational database, I'd just have a table in between that
>> stored the room id, the furniture id, and the furniture count. I'm not
>> 100% sure how to accomplish this with django's models. Should I have a
>> third model: 'count' with the manytomany room relationship, and the
>> manytomany furniture relationship, along with an integer count? Is this
>> the correct, clean way to do it? I'm not sure how that will translate to
>> my views code when I want to find a room that **only** has chairs and
>> tables.
>>     
>
> At the moment you do it this way:
> http://www.djangoproject.com/documentation/models/m2m_intermediary/ (the
> Writer model is the intermediary).
>
> "Coming Soon" (for values of 'soon' that mean 'yeah, when we get time'),
> we'll add a "through" attribute to ManyToManyField so that you can
> specify the intermediate model (which will be written just the same as
> above) but still have the benefit of direct many-to-many access when you
> need it. The only drawback of the manual intermediate table at the
> moment is that if you want to get from Reporter to Article, you need to
> manually write in the Writer model in the query construction, which is a
> little less neat than for a ManyToManyField.
>
> Regards,
> Malcolm
>
>   


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