如何添加FlatPageAdmin?

时间:2017-05-13 16:39:38

标签: django

欢迎朋友

我需要你的帮助。

我想使用FlatPageAdmin。如下例所示。

from django.contrib import admin

class FlatPageAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {
            'fields': ('url', 'title', 'content', 'sites')
        }),
        ('Advanced options', {
            'classes': ('collapse',),
            'fields': ('registration_required', 'template_name'),
        }),
    )

https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.contrib.admin.ModelAdmin.fieldsets

enter image description here

当然可能很简单,但我不知道如何做到这一点。

这是我的admin.py

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from .models import Order
from django.http import HttpResponse
from django.core.urlresolvers import reverse

class OrderAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'email']
    list_filter = ['name']

admin.site.register(Order, OrderAdmin)

我正在努力。但无论我做什么,我总是得到:

    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

虽然我添加了

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)

如何解决问题?

感谢您的帮助

更新

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'crispy_forms',
    'order',
)

1 个答案:

答案 0 :(得分:0)

好朋友 - 作品

我不知道这是不是最好的方式,但只是我改变了这一行:

from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from .models import Order
from django.core.urlresolvers import reverse

class FlatPageAdmin(admin.ModelAdmin):
    fieldsets = (
        (None, {'fields': ('xxx', 'xxx', 'email')}),
        (_('Advanced options'), {
            'classes': ('collapse', ),
            'fields': (
                'xxx',
            ),
        }),
    )
    list_display = ['xx', 'xx', 'xx', 'xx',
                    'xxx',
                    'xx', 'xx', xx]
    list_filter = ['x', 'x', 'x']

admin.site.register(Order, FlatPageAdmin)

这解决了我的问题,并希望这将在未来帮助你。