"Did you know about mutation? :-)" I was expecting this one! Well thanks a lot!!
2007/1/10, Ivan Sagalaev <[EMAIL PROTECTED]>: > > > Sebastien Armand [Pink] wrote: > > class Person(models.Model): > > ... > > mother = models.ForeignKey('Person') > > ... > > > > Will this work? > > Use models.ForeignKey('self') > > > For example if I've got a Body class and a Legs class, I know that I'll > > never have a body with more than 2 legs > > Did you know about mutation? :-) > > > and it would be easier to have a > > leftLeg = ForeignKey(Leg) field > > and a > > rightLeg = ForeignKey(Leg) field > > > > but this causes many errors when I try to validate my model. > > Upon seeing a ForeignKey Django tries to create backward accessors from > the parent model to children. In your case it should be "Leg.body_set" > that will fetch all Legs with a ForeignKey to a particular Body. > > However since you have two ForeignKeys to the same model Django needs to > have two such relations: all bodies for a LeftLeg and all bodies for a > RightLeg. The only problem that it doesn't know how to _name_ these > relations. It certainly can't have two different "body_set"s on a Leg. > So the only thing that it asks you is to choose two names for the > relations: > > leftLeg = models.ForeignKey(Leg, related_name='bodies_if_left') > rightLeg = models.ForeignKey(Leg, related_name='bodies_if_right') > > My naming skills are known to be lousy so choose your own according to > what these things really mean. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---