如何将一个类添加到Django Python的管理员页面?

2024-04-26 00:35:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在django做一个小网站。当我尝试使用以下代码向管理页添加按钮时:

 from django.contrib import admin

 # Register your models here.
  from .models import profile

 class profileAdmin(admin.Modeladmin):
      class Meta: 
           Model =  profile
 admin.site.register(profile, profileAdmin)

这是添加按钮到管理页面的代码。你知道吗

 from django.db import models

 # Create your models here.
class profile(models.Model):
      name = models.CharField(max_length=50)
      desc = models.TextField(default = 'default user description')
      job = models.CharField(max_length=20)

      def _unicode_(self):
          return self.name

这是按钮的代码。我还知道,配置文件应用程序,其中包含这个按钮和管理页面已被添加到安装应用程序,并正在运行。当我尝试进行迁移时,系统会提示我这个错误。你知道吗

AttributeError:模块'django.contrib.admin管理员'没有属性'Modeladmin'


Tags: django代码fromimportyourmodelhereadmin