未创建 class table(未在管理员中看到)
Not created class table (not seen in Admin)
我创建了新模型:
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
管理中的Byt 我没有看到新的table 订阅
什么问题?
创建模型不足以在管理面板中显示它们。您需要 "register" 这些模型。
在您定义模型的 app
中,通常有一个 admin.py
文件,您可以在其中注册您的模型,例如:
# app/admin.py
from django.contrib import admin
from app.models import Subscribe
admin.site.<b>register(</b>Subscribe<b>)</b>
如果您想将特定行为附加到此类模型管理员(例如通过添加操作),您可以制作一个 ModelAdmin
class,并指定该行为,如documentation on ModelAdmin
.
我创建了新模型:
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
管理中的Byt 我没有看到新的table 订阅
什么问题?
创建模型不足以在管理面板中显示它们。您需要 "register" 这些模型。
在您定义模型的 app
中,通常有一个 admin.py
文件,您可以在其中注册您的模型,例如:
# app/admin.py
from django.contrib import admin
from app.models import Subscribe
admin.site.<b>register(</b>Subscribe<b>)</b>
如果您想将特定行为附加到此类模型管理员(例如通过添加操作),您可以制作一个 ModelAdmin
class,并指定该行为,如documentation on ModelAdmin
.