I have 2 models and a Foreign Key between them
class League(models.Model):
"""
League Info
"""
def __unicode__(self):
return self.name
FUTBOL = 'FUT'
FUTBOLITO = 'FT7'
OTRO = 'OTH'
LEAGUE_CHOICES = (
(FUTBOL, 'Fútbol'),
(FUTBOLITO, 'Futbolito'),
(OTRO, 'Otro'),
)
MASCULINO = 'M'
FEMENINO = 'F'
MULTIPLE = 'A'
SEX_CHOICE = (
(MASCULINO, 'Masculino'),
(FEMENINO, 'Femenino'),
(MULTIPLE, 'Femenino y Masculino'),
)
league_type = models.CharField(null=False, blank=False, max_length=3, choices=LEAGUE_CHOICES, default=FUTBOLITO)
league_sex = models.CharField(max_length=2, choices=SEX_CHOICE, default=MASCULINO)
name = models.CharField(null=False, blank=False, max_length=200)
The second Model is
class Division(models.Model):
"""
Division of a League e.g. Junior, Senior; First Division, Second Division
"""
def __unicode__(self):
return self.name
MASCULINO = 'M'
FEMENINO = 'F'
MULTIPLE = 'A'
SEX_CHOICE = (
(MASCULINO, 'Masculino'),
(FEMENINO, 'Femenino'),
(MULTIPLE, 'Femenino y Masculino'),
)
name = models.CharField(null=False, blank=False, max_length=200) # name required
league = models.ForeignKey(League, blank=False)
league_name = league.name
league_type = league.league_type
league_sex = league.league_sex
when I run syncdb i got an error : AttributeError: 'ForeignKey' object has no attribute 'league_type'
I got the same error with league_sex, but don't get it with league_name, which seems to be ok. The app is on the setiings Installed Apps
league_name = league.namethis is not the right way to define model fields. What are you trying to do here?