On Mar 6, 2010, at 10:37 AM, Matthew Warren wrote:

Hi,

I have a model like the following;

class elements(models.Model):
    name=models.CharField(max_length=21)


class grouping(models.Model):
    name=models.CharField(max_length=48)
    elementgroup=models.ForeignKey(elements)



I'm assuming this means that a grouping may relate to multiple elements, but an element may only be related to a single group.

It's the other way around. As written, a grouping can only relate to a single element, but each element can have any number of groupings. You can think of the ForeignKey field a pointer, pointing from the grouping to the element. It's a real field, so it can only have one value per instance. If what you want is for one element to only have a single grouping, but each grouping to have multiple elements, the ForeignKey goes in the element, not the grouping.

--
-- Christophe Pettus
   x...@thebuild.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-us...@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