Re: How do I make a self-referential Many to Many relationship optional?
Austin here is an object from the model of one of my applications. The self referential many-to-many relationship is optional and works find in the admin interface. Note that you may or may not need the symmetrical part. class Customer(models.Model): """ A Customer is anyone we have sold to or to whom we would like to sell. It can also be someone related to the process of selling, like a Dealer. Customers can be associated with other Customers. For example, a School may be associated with a District and a Region and a Dealer and a Co-op. """ name = models.CharField(maxlength=200) customer_type=models.ForeignKey(CustomerType) associated_with = models.ManyToManyField("self",null=True,blank=True,symmetrical=False) notes = models.TextField(blank=True,default="") def __str__(self): return self.name class Admin: list_display=('name','customer_type') search_fields= ['name',] list_filter=['customer_type'] --gordy --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: How do I make a self-referential Many to Many relationship optional?
And for the record, blank=True does make it not required. :-) Thanks guys! -- Austin Govella Thinking & Making: IA, UX, and IxD http://thinkingandmaking.com [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: How do I make a self-referential Many to Many relationship optional?
On 12/13/06, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: > On 12/14/06, Austin Govella <[EMAIL PROTECTED]> wrote: > > How do I make the self-referential Many to Many relationship optional? > > Um... m2m relationships are optional by definition. A ManyToMany field > sets up an intermediate table, but adds nothing to the model table > itself. You are not required to put anything in the intermediate > table, so the m2m relationships are optional (of a fashion). When I add a person using the default Admin app, it gives me an error and says the related field is required. But my model doesn't explicitly require anything: related = models.ManyToManyField('self', verbose_name="Related Artists", filter_interface=models.HORIZONTAL) Is this a bug in the Admin stuff, or am I doing something wrong? -- Austin Govella Thinking & Making: IA, UX, and IxD http://thinkingandmaking.com [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: How do I make a self-referential Many to Many relationship optional?
Russell Keith-Magee wrote: > Um... m2m relationships are optional by definition I wrote: > Try to add "null=True". Sorry Austin; too quick reply... and maybe it's time to go to bed :-) I confused your m2m with a normal foreign-key. Massimiliano --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: How do I make a self-referential Many to Many relationship optional?
On 12/14/06, Austin Govella <[EMAIL PROTECTED]> wrote: > blank=TRUE returns an error: > "name 'TRUE' is not defined" Oh.. and the obvious error here - The Python boolean truth symbol is 'True', not 'TRUE' - the error you are getting is because the symbol TRUE is undefined. Yours, 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?hl=en -~--~~~~--~~--~--~---
Re: How do I make a self-referential Many to Many relationship optional?
On 12/14/06, Austin Govella <[EMAIL PROTECTED]> wrote: > > How do I make the self-referential Many to Many relationship optional? Um... m2m relationships are optional by definition. A ManyToMany field sets up an intermediate table, but adds nothing to the model table itself. You are not required to put anything in the intermediate table, so the m2m relationships are optional (of a fashion). In your case, you have a Person table with an m2m relation on self; if you add a whole lot of Person instances, there will be no relations defined; no single person is required to have a relation. If you want to add relations, you can, but they are completely optional. Or have I missed what you are trying to acheive? Yours, 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?hl=en -~--~~~~--~~--~--~---
Re: How do I make a self-referential Many to Many relationship optional?
Austin Govella wrote: > How do I make the self-referential Many to Many relationship optional? Try to add "null=True". Massimiliano --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How do I make a self-referential Many to Many relationship optional?
I have a model for people and each person can have many other people as family: related = models.ManyToManyField('self', verbose_name="Related", filter_interface=models.HORIZONTAL, blank=TRUE) Right now, the field is required, but I want it to be optional, but blank=TRUE returns an error: "name 'TRUE' is not defined" How do I make the self-referential Many to Many relationship optional? Many thanks, -- Austin Govella Thinking & Making: IA, UX, and IxD http://thinkingandmaking.com [EMAIL PROTECTED] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---