Hi Peter,

  While your proposed solution would work for the prototyping example
I've given, I have 3 more arching themes like Show and probably
another 4-5 content types like photo and articles. The main idea here
is to be able to select an arbitrary element, be it a photo, video,
article, etc. and display all of its related content, regardless of
content type, within the theme (aka Show). As an ancillary goal, I
need to ensure I'm not generating a ton of expensive queries for each
of these lookups as this site will be serving a large number of users.
 As far as I can tell, abstracting these relationships is the best way
to go about the problem, its just the method of abstraction that I'm
unsure on.

 -justin

On Sun, Feb 15, 2009 at 10:32 AM, Peter Herndon <tphern...@gmail.com> wrote:
>
> Hi Justin,
>
> I can't view your code at the moment, but it seems to me you want a
> ForeignKey on Article to Show, another FK on Photo to Show, an M2M
> from Article to Photo, and a custom manager on Show, or some other
> custom method, that returns both Articles and Photos.  The latter
> might best be accomplished by having Articles and Photos inherit from
> some common model, and have Show pull from that common ancestor and
> then descend to the specific type as needed.  The common model would
> be where you'd have the FK to Show, thinking about it, and then you
> wouldn't need a custom method on Show, you could just use std methods.
>
> ---Peter
>
> On 2/12/09, Justin Lilly <justinli...@gmail.com> wrote:
>>
>> Hi all.
>>
>>   I have a project where I need to assign multiple models to each
>>   other via some many to many relationship.
>>
>>   There are a few main players in my prototype: Articles, Photos and
>>   Shows. Shows has many Articles and Photos. Article has many Photos,
>>   but has one Show. Photos has one Show, but has many Articles. (Might
>>   make more sense below) There will be more models involved in this
>>   process when this app goes to production, but these 3 will do for
>>   prototyping.
>>
>>   My initial thought was to have an intermediate model with 2 generic
>>   relationships. I think this is going to be too costly in terms of
>>   performance as I'll need to run 2x the queries per lookup. One to
>>   check if my lookup object is referenced in the first generic
>>   relationship, then to see if its referenced in the 2nd one.
>>
>>   The next idea was to have a self-referential m2m field for my models
>>   to inherit from. The issue there is the lookup returns objects whose
>>   type is that of the parent model, not the child model.
>>
>>   I'm looking for a way to accomplish queries similar to this:
>>
>>   >>> myshow
>>   <show4>
>>   >>> myshow.related.all()
>>   [<photo1>, <photo2>, <article3>, <article4>, <article9>]
>>   >>> photo1 = myshow.related.all()[0]
>>   >>> photo1.related.all()
>>   [<article3>, <show4>, <article9>, <article4>]
>>
>>   The self referential model code I was using can be found at
>>   http://dpaste.com/119897/ and an ipython session at
>>   http://dpaste.com/119898/ . I feel as if I may be stretching what
>>   model inheritance was meant for or at least what its currently
>>   capable of.
>>
>>   Although everyone says it, the solution will need to scale to a
>>   large number of users as it will be used in a very large
>>   dynamic-content site. This is the core of the content plan (to
>>   present various content types based on a given "pivot point", in the
>>   illustrated case above, shows).
>>
>>   Looking for any advice or help you may be able to provide.
>>
>>  -justin
>>
>> >
>>
>
> >
>



-- 
Justin Lilly
Web Developer/Designer
http://justinlilly.com

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