Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
I started composing a reply to your response, and then realized that I had erroneously constructed a mental one-to-one model of the relationship rather than one-to-many. You're absolutely right, what I was trying to do doesn't make any sense. Whoops :) Mike On May 13, 2:28 pm, "Scott Moonen

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, I think I understand what you're getting at, given your comment referring to the "unnecessary table and associated join". I think you want to be able to say "ManyToOneField" in Place and have it reach back into the Photo model and insert a NULLable "place_id" column. That's problematic f

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Richard Dahl
A third alternative is to use a GenericForeignKey. Although this may add too much complexity. Put the GenericForeignKey in a model called PhotoTag and create a M2M relationship between it and Photo and use it to select either a Place or a UserProfile, i.e. class PhotoTag(models.Model) conten

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
Sure. OOM relationships can typically be broken down along two dimensions: cardinality and directionality. cardinality: DIRECTIONALITY -- One-to-one: ONE-WAY, BI-WAY One-to-many: ONE-WAY, BI-WAY Many-to-many: ONE-WAY, BI-WAY The cardinality i

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, can you elaborate on what you mean by "forcing bi-directional relationships"? The ManyToManyField approach really is, I think, the "right" way to do it. If you think about it, a hypothetical ManyToOneField in your case would work almost exactly like the ManyToManyField. The join table wo

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
Thanks much, Scott. They both seem a bit hacky, but it gives me something to work with anyway. I recognize the motivation for forcing bi-directional relationships in Django was done to keep things DRY[1], but does anyone know if there's been any discussion about maybe relaxing this constraint?

Re: Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Scott Moonen
Michael, you have two alternatives: 1. Create ManyToManyField fields in the UserProfile and Place models, pointing to Photo. "ManyToManyField" may seem a bit odd since you really have a many-to-one relation, but it will work as you expect, creating a join table connecting each pair of

Having a Many-to-One relationship with multiple other models

2008-05-13 Thread Michael Burton
I have some Places and I have some Users in my database. I'd like to be able to associate some Photos with each. class Photo(models.Model): # a model that represents a photo class UserProfile(models.Model): # has a list of Photos class Place(models.Model): # has a list of Pho