Re: Help with some models inheritance and the use of default
On May 6, 3:56 pm, Felixwrote: > I have the next models: > > class Place(models.Model): > currency = models.CharField(_('currency'), max_length=128, > blank=True, null=True) > language = models.CharField(_('official language'), > max_length=128, blank=True, null=True) > class Meta: > abstract= True > > class Country(Place): > country = models.CharField(_('country'), max_length = 100) > continent = models.CharField(_('continent'), > choices=CONTINENT_CHOICES, max_length = 2, blank = True, null=True) > president = models.CharField(_('president'), max_length = 100, > blank = True, null=True) > > class City(Place): > city = models.CharField(_('city'), max_length=100) > country = models.ForeignKey(Country) > language = ?? > > How can I set language of the to the language of its country's > language by default? > Thanks for reading why won't you use non-abstract inheritance? that way all your cities would inherit all the properties of the respective country instance, language including V --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Help with some models inheritance and the use of default
On 5/6/2009 6:56 AM, Felix wrote: > I have the next models: > > class Place(models.Model): > currency = models.CharField(_('currency'), max_length=128, > blank=True, null=True) > language = models.CharField(_('official language'), > max_length=128, blank=True, null=True) > class Meta: > abstract = True > > class Country(Place): > country = models.CharField(_('country'), max_length = 100) > continent = models.CharField(_('continent'), > choices=CONTINENT_CHOICES, max_length = 2, blank = True, null=True) > president = models.CharField(_('president'), max_length = 100, > blank = True, null=True) > > class City(Place): > city = models.CharField(_('city'), max_length=100) > country = models.ForeignKey(Country) > language = ?? > > How can I set language of the to the language of its country's > language by default? I think the easiest thing is to put the logic in your `City.save()` method, since you'll have access to the instance's country at that point. Then it's just a matter of looking up the country to language mapping somewhere. -- George --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---