I have a foreign key linking two models. One is called ZumaDirectors, the other ZumaConsolidated. For some reason I cannot access fields on ZumaConsolidated from ZumaDirectors using foreign key. I can do this without a problem on ZumaDirectors with a foreign key linked to another table.
I want to be able to do eg. p=ZumaDirectors.all_directors_key.company_name
but when I try this I get this error: "Attribute error: long object has no attribute 'company_name'. The same error applies for any field I try and access.
Here are the models. I am tearing my hair out and would be glad for any help.

class ZumaConsolidated(models.Model):
    id = models.IntegerField(primary_key=True, db_column='id')
    id_no = models.TextField(blank=True)
    zuma_details_first_name = models.TextField(db_column='Zuma_details_First_name', blank=True) # Field name made lowercase.
    zuma_details_surname = models.TextField(db_column='Zuma_details_Surname', blank=True) # Field name made lowercase.
    first_name = models.TextField(blank=True)
    surname = models.TextField(blank=True)
    type = models.TextField(blank=True)
    status = models.TextField(blank=True)
    doa = models.DateField(db_column='DOA', blank=True) # Field name made lowercase.
    company_name = models.TextField(db_column='Company_name', blank=True) # Field name made lowercase.
    registration_number = models.TextField(db_column='Registration_number', blank=True) # Field name made lowercase.
    registration_date = models.DateField(db_column='Registration_Date', blank=True) # Field name made lowercase.
    company_status = models.TextField(db_column='Company_status', blank=True) # Field name made lowercase.
    registered_address = models.TextField(db_column='Registered_address', blank=True) # Field name made lowercase.

    def __unicode__(self):
        return ('%s %s %s') % (self.zuma_details_first_name, self.zuma_details_surname, self.company_name)


    class Meta:
        db_table = u'zuma_consolidated'

class ZumaDirectors(models.Model):
    all_directors_key = models.ForeignKey(ZumaConsolidated, db_column='All_directors_key') # Field name made lowercase.
    companies = models.ForeignKey(ZumaCompanies, null=True, db_column='companies', blank=True)
    first_name = models.TextField(blank=True)
    surname = models.TextField(blank=True)
    type = models.TextField(blank=True)
    status = models.TextField(blank=True)
    doa = models.DateField(db_column='DOA', blank=True) # Field name made lowercase.

    def __unicode__(self):
        return ('%s %s') % (self.first_name, self.surname)

    
    class Meta:
        db_table = u'zuma_directors'

Hm, your model is regarded as a long instead of a model, can you paste the views.py or full shell code you are trying to execute?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.