Might try removing the default from x_pos then try setting it by overriding the save method
https://docs.djangoproject.com/en/1.4/topics/db/models/#overriding-predefined-model-methods K On Saturday, May 24, 2014 8:28:17 PM UTC-7, Robbie Edwards wrote: > > Hi, I have some code like such... > > > def gen_planet_pos( max_dim ): > return random.randint( 0, max_dim ) > > > 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 > shell. I'm not sure what to do to prevent this error. Your help is > appreciated. > > robbie > -- 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 [email protected]. To post to this group, send email to [email protected]. 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/c6856a3e-6be2-407e-9f23-d3e815733552%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

