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 models. 2. Create two ForeignKey fields in Photo, one to UserProfile and one to Photo, with null=True. Yes, this is a bit ugly. :)
-- Scott On Tue, May 13, 2008 at 2:24 PM, Michael Burton <[EMAIL PROTECTED]> wrote: > > 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 Photos > > > Normally, if i were using another ORM framework, I would make my Place > have a list of photos, and I'd make my UserProfile have a list of > photos, and I'd leave my Photo model alone. However, the Django way > of doing things requires that I put a ForeignKey into my Photo model > to establish the one-to-many. > > The problem is, sometimes Photo's ForeignKey will point to a > UserProfile and sometimes to an Place. How can I have both my > UserProfile and Place models point to Photos? > > Thanks in advance, > Mike > > > -- http://scott.andstuff.org/ | http://truthadorned.org/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---