Marijus
Marijus

Reputation: 4365

django custom field in admin inline

Here's admin.py:

class AnsweredQuestionInline(ReadonlyTabularInline):
    model = AnsweredQuestion
    fields = ('question', 'selected_choice', 'one_answer')

    def one_answer(self, obj):
        return obj.get_answer()


class CompletedTestAdmin(admin.ModelAdmin):
    inlines = [AnsweredQuestionInline]

When I go to completed test admin interface I get this error:

Exception Type: FieldError at /admin/tests/completedtest/5/
Exception Value: Unknown field(s) (one_answer) specified for AnsweredQuestion

Is it possible to add custom fields for django's inline admin ? If so what am I doing wrong ?

Upvotes: 5

Views: 7542

Answers (1)

All you need is readonly_fields = ('one_answer', ) in your AnsweredQuestionInline class

Upvotes: 22

Related Questions