[Answer]-Django: foreign key display

1👍

Solved!

When creating a foreign key, django saves the field with the original name + “_id”.
So my field “prelexRespProposId1” was in fact named “prelexRespProposId1_id”. I had to use the latter name to have my code working!

My models:

class ActsInformationModel(models.Model):
    prelexRespProposId1=models.ForeignKey('RespProposModel', related_name='prelexRespProposId1', blank=True, null=True, default=None)

My view:

...
dataDic["prelexRespProposId1_id"]=RespProposModel.objects.get(respPropos=respPropos)
print dataDic["prelexRespProposId1_id"].id #display 1 -> OK
act=ActsInformationModel.objects.get(...)
act.__dict__.update(dataDic)
print "act.prelexRespProposId1_id", act.prelexRespProposId1_id #display 1 -> Solved!!!
👤rom

Leave a comment