Tuesday, January 25, 2011

Re: method of method

On 25 jan, 12:41, Jaroslav Dobrek <jaroslav.dob...@gmail.com> wrote:
> >> What happens ?
>
> I get this error message when I run manage.py syncdb:
>
> AttributeError: 'ForeignKey' object has no attribute 'producer'
>
> >> And what did you expect to happen ?
>
> I want the 'country_of_origin' of cars to be the string that is stored
> in their producer's 'country_of_origin':

Do you mean that you want Car to have a country_of_origin model.Field
(IOW: the yourapp_car table to have a country_of_origin column) and
copy the related Producer.country_of_origin field's value in it, or
just Car instances to have a "country_of_origin" attribute that is
just a shortcut for self.producer.country_of_origin ?


> class CarProducer(models.Model):
>   country_of_origin = models.CharField(max_length=200)
>
> class Car(models.Model):
>     producer = models.ForeignKey(CarProducer)
>     country_of_origin = producer.country_of_origin

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment