未创建类表(在管理员中看不到)

时间:2018-09-30 10:15:33

标签: django django-models django-migrations

我创建新模型:

class Subscribe(models.Model):
   title = models.CharField(max_length=30);
   subscribers = models.ManyToManyField(User)

创建迁移:

E:\Dropbox\djagoBlog\blog>python manage.py migrate --fake account zero
Operations to perform:
  Unapply all migrations: account
Running migrations:
  No migrations to apply.

运行迁移:

python manage.py migrate account
Operations to perform:
  Apply all migrations: account
Running migrations:
  Applying account.0001_initial... OK

在Admin中,我看不到新表Subscribe

什么问题?

1 个答案:

答案 0 :(得分:0)

创建模型 不足以在管理面板中显示它们。您需要“注册”这些模型。

在定义模型的app中,通常会有一个admin.py文件,您可以在其中注册模型,例如:

# app/admin.py

from django.contrib import admin
from app.models import Subscribe

admin.site.register(Subscribe)

如果要将特定行为附加到此类模型管理员(例如,通过添加操作),则可以制作ModelAdmin类,并按照documentation on ModelAdmin中的指定指定该行为。