ManyToMany with related_name?

2006-04-12 Thread Dave St.Germain
I'm trying to create a model that relates back to itself with a ManyToManyField.  Here's my model:class PressRun(models.Model):    starttime = models.DateTimeField(db_index=True)    endtime = models.DateTimeField
(validator_list=[endAfterStartValidator])    name = models.CharField(maxlength=100,blank=True)    recurringitem = models.ForeignKey(RecurringPressRun,blank=True,null=True)    edition = models.IntegerField(choices=EDITION_CHOICES,blank=True,null=True)
    press_id = models.IntegerField(choices=PRESS_CHOICES,blank=True,default=1)    insert_into = models.ManyToManyField('self',  null=True,  blank=True,  related_name='insert')
The problem is that the model doesn't seem to use the related_name option.  PressRun objects have an insert_into property, but no insert property.  I'm actually trying to say that the result of a PressRun can be "inserted" into another PressRun, but I don't want to make a separate object (like PressRunInsert or something).  I'd like to use a simple ManyToMany, but the objects don't have a distinction between "inserted into" and "insert of".  
Does that make sense?Dave

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


Re: ManyToMany with related_name?

2006-04-12 Thread Russell Keith-Magee
On 4/13/06, Dave St.Germain <[EMAIL PROTECTED]> wrote:
I'm trying to create a model that relates back to itself with a ManyToManyField.  Here's my model:I'd like to use a simple ManyToMany, but the objects don't have a distinction between "inserted into" and "insert of".  
Does that make sense?Yup. The problem here is that Django assumes that if you have a ManyToMany field on self, then the relationship is symmetrical: for example:class Person:
   friend = ManyToManyField('self')If I am your friend, then presumably you are my friend. To avoid confusion, the reverse representation of the relationship (person_set, or whatever related_name specifies) is not added to instances of Person.
Obviously, there are some use cases (such as yours) where this is not the case - to handle these, you need to set symmetrical=False:
insert_into = models.ManyToManyField('self',
  null=True,
  blank=True,
  related_name='insert'
  symmetrical=False)

This will add the related_name member on the related object, and will be a distinct set; adding to PressRun.insert_into is not the same as adding to PressRun.insertHope this helps,Russ Magee %-)

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