I've got the exact same problem than him : Can "list_display" in a Django ModelAdmin display attributes of ForeignKey fields?
I want to see the question on the answer admin. I did the same thing than in the answer but got this error:
'Answer' object has no attribute 'question'
here is my code(question can have many possible answer):
class Question(models.Model):
question = models.CharField(max_length=255)
class Answer(models.Model):
question = models.ForeignKey('Question')
answer = models.CharField(max_length=255)
my admin:
class AnswerAdmin(admin.ModelAdmin):
model = Answer
list_display = ['answer', 'get_question', ]
def get_question(self, obj):
return obj.question.question
admin.site.register(Answer, AnswerAdmin)