Home > OS >  cannot use admin.modeladmin subclass
cannot use admin.modeladmin subclass

Time:03-24

I've started Django for 2 days and I get stuck in this section. I want to change the admin section but my class couldn't inherit from (admin.modeladmin). when i want to use list_display,nothing load, and python give me this error:

<class 'django.contrib.auth.admin.GroupAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'title', which is not a callable, an attribute of 'GroupAdmin', or an attribute or method on 'auth.Group'. <class 'django.contrib.auth.admin.GroupAdmin'>: (admin.E108) The value of 'list_display[1]' refers to 'view', which is not a callable, an attribute of 'GroupAdmin', or an attribute or method on 'auth.Group'.

from django.contrib import admin
from .models import articles

class articlesAdmin(admin.ModelAdmin):
    list_display=("title","view")
admin.site.register(articles)

how can i solve this?

CodePudding user response:

admin.site.register requires two parameters: the model object and the admin class.

admin.site.register(articles, articlesAdmin)

(As an aside, it's conventional to name all classes, including models, in PascalCase and singular, so Article instead of articles and ArticleAdmin instead of articlesAdmin.)

The error seems to hint that you've maybe somehow edited django.contrib.auth.GroupAdmin instead. If that's the case, I'd recommend uninstalling the Django library and reinstalling the same version, so you're sure to have unmodified code.

CodePudding user response:

Try:

from django.contrib import admin
from .models import articles

class articlesAdmin(admin.ModelAdmin):
    list_display = ("title","view",)
admin.site.register(articles,articlesAdmin)
  • Related