Sunday, May 25, 2014

Re: AttributeError when trying to reference ForeignKey attributes

On Sat, 24 May 2014 20:28:17 -0700 (PDT), Robbie Edwards
<robbie.edwards@gmail.com> declaimed the following:

>
>class Universe( models.Model ):
> width = models.IntegerField( default=100 )
> ...
>
>
>class Planet( models.Model ):
> universe = models.ForeignKey( Universe )
> ...
> x_pos = models.IntegerField( default=gen_planet_pos( universe.width ) )
>
>
>When I try to use this, I get "AttributeError: 'ForeignKey' object has no
>attribute 'width'". That message appears when I try to even enter the

As an outsider, I'd think the problem is that during the class
definitions you do not have any INSTANCE (record) to refer to... But
gen_planet_pos() is being called DURING the definition of the Planet class.

--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ra74o9hd7micdiqbj77kteumtt1d48hfbe%404ax.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment