0

と の 2 つのモデルがQuestionありQuestionChoiceます。QuestionChoice には、Question を指す ForeignKeyfield があります。これらを管理ビューにインライン スタック ビューとして表示したいのですが、エラーが発生します。

モデル:

class Question(models.Model):
    PROFILE = 0
    EVENT_REPORT = 1
    UNIVERSITY_REPORT = 2
    USER_REPORT = 3
    TYPE_LIST = [PROFILE, EVENT_REPORT, UNIVERSITY_REPORT, USER_REPORT]
    TYPE_CHOICES = (
        (PROFILE, 'Profile'),
        (EVENT_REPORT, 'Event Report'),
        (UNIVERSITY_REPORT, 'University Report'),
        (USER_REPORT, 'User Report'),
    )
    description = models.CharField(max_length=100)
    type =models.IntegerField(choices=TYPE_CHOICES, default=PROFILE)

    def __str__(self):
        return self.description


class QuestionChoice(models.Model):
    description = models.CharField(max_length=100)
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    answer = models.CharField(max_length=100, blank=True)

    def __str__(self):
        return self.question.first().description + ' ' + self.description

管理者:

admin.site.register(QuestionChoice)
class QuestionChoiceInline(admin.StackedInline):
    model = QuestionChoice
    can_delete = True
    verbose_name_plural = 'Question Choices'
    fk_name = "question"


class CustomQuestionAdmin(UserAdmin):
    inlines = (QuestionChoiceInline, )

    def get_inline_instances(self, request, obj=None):
        if not obj:
            return list()
        return super(CustomQuestionAdmin, self).get_inline_instances(request, obj)

admin.site.register(Question, CustomQuestionAdmin)

しかし、私はこのエラーが発生しています:

ERRORS:
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E019) The value of 'filter_horizontal[0]' refers to 'groups', which is not an attribute of 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E019) The value of 'filter_horizontal[1]' refers to 'user_permissions', which is not an attribute of 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E033) The value of 'ordering[0]' refers to 'username', which is not an attribute of 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'username', which is not a callable, an attribute of 'CustomQuestionAdmin', or an attribute or method on 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'email', which is not a callable, an attribute of 'CustomQuestionAdmin', or an attribute or method on 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'first_name', which is not a callable, an attribute of 'CustomQuestionAdmin', or an attribute or method on 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E108) The value of 'list_display[3]' refers to 'last_name', which is not a callable, an attribute of 'CustomQuestionAdmin', or an attribute or method on 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E108) The value of 'list_display[4]' refers to 'is_staff', which is not a callable, an attribute of 'CustomQuestionAdmin', or an attribute or method on 'userprofile.Question'.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'is_staff', which does not refer to a Field.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E116) The value of 'list_filter[1]' refers to 'is_superuser', which does not refer to a Field.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E116) The value of 'list_filter[2]' refers to 'is_active', which does not refer to a Field.
<class 'userprofile.admin.CustomQuestionAdmin'>: (admin.E116) The value of 'list_filter[3]' refers to 'groups', which does not refer to a Field.

私が間違っていることはありますか?

4

1 に答える 1