Django - 无法使list_display工作

时间:2017-09-18 15:39:40

标签: python django

这是我的代码:

from django.contrib import admin
from django.contrib.admin import ModelAdmin
from .models import Feedback
from django import forms

class FeedbackForm(forms.ModelForm):

    class Meta:
        model = Feedback
        fields = '__all__'

class FeedbackAdmin(ModelAdmin):
    form = FeedbackForm
    search_fields = ('name', 'category', 'email', 'subject')
    list_display = ('name', 'category', 'email', 'subject', 'is_read')
    list_editable = ('is_read', )

admin.site.register(Feedback)

当我运行它时,我看不到search_fieldslist_displaylist_editable。 我运行服务器时也没有收到任何错误消息。 我做错了什么?

3 个答案:

答案 0 :(得分:4)

您实际上没有使用过您的FeedbackAdmin类。您需要将其传递给register

admin.site.register(Feedback, FeedbackAdmin)

答案 1 :(得分:2)

class FeedbackAdmin(ModelAdmin):
    form = FeedbackForm
    search_fields = ['name', 'category', 'email', 'subject']
    list_display = ['name', 'category', 'email', 'subject', 'is_read']
    list_editable = ['is_read']

admin.site.register(Feedback,FeedbackAdmin)

你没有注册modeladmin类

答案 2 :(得分:1)

乍一看,您似乎没有注册管理员课程

admin.site.register(Feedback, FeedbackAdmin)