Django models admin中的Django动态模型寄存器

Django models admin中的Django动态模型寄存器,django-models,django-admin,Django Models,Django Admin,我使用的是django 1.11,我试图通过引用这个链接来创建django动态模型,执行它运行的每一步都没有任何问题,但是我如何在django管理面板中看到这个创建的表呢 action.py 在控制台中: from action import create_model from django.db import models fields = { 'first_name': models.CharField(max_length=255), 'last_name': model

我使用的是django 1.11,我试图通过引用这个链接来创建django动态模型,执行它运行的每一步都没有任何问题,但是我如何在django管理面板中看到这个创建的表呢

action.py

在控制台中

from action import create_model
from django.db import models

fields = {
    'first_name': models.CharField(max_length=255),
    'last_name': models.CharField(max_length=255),
    '__str__': lambda self: '%s %s' (self.first_name, self.last_name),
}

options = {
    'ordering': ['last_name', 'first_name'],
    'verbose_name': 'valued customer',
}

admin_opts = {}

model = create_model('Person', fields,
    options=options,
    admin_opts=admin_opts,
    app_label='form',
    module='project.app.model',
)
我可以通过查看字段的数量

len(model._meta.fields)

但是我不知道,如何在admin中注册创建的模型,以及在
admin_opts={}
中会出现什么参数,我如何进行makemigrationsmigrate,我如何在views.py中访问此模型,我将从那里导入此模型。你们能帮我一下吗,这将对我非常有用,请提前感谢。

我想您忘记执行此功能了

def install(model):
from django.core.management import sql, color
from django.db import connection

# Standard syncdb expects models to be in reliable locations,
# so dynamic models need to bypass django.core.management.syncdb.
# On the plus side, this allows individual models to be installed
# without installing the entire project structure.
# On the other hand, this means that things like relationships and
# indexes will have to be handled manually.
# This installs only the basic table definition.

# disable terminal colors in the sql statements
style = color.no_style()

cursor = connection.cursor()
statements, pending = sql.sql_model_create(model, style)
for sql in statements:
    cursor.execute(sql)

我想你忘记执行这个函数了

def install(model):
from django.core.management import sql, color
from django.db import connection

# Standard syncdb expects models to be in reliable locations,
# so dynamic models need to bypass django.core.management.syncdb.
# On the plus side, this allows individual models to be installed
# without installing the entire project structure.
# On the other hand, this means that things like relationships and
# indexes will have to be handled manually.
# This installs only the basic table definition.

# disable terminal colors in the sql statements
style = color.no_style()

cursor = connection.cursor()
statements, pending = sql.sql_model_create(model, style)
for sql in statements:
    cursor.execute(sql)
这是来自github的源代码,尝试它而不是sql\u model\u create,我尝试在我的项目中取得成功,这是真的

我努力工作了很长时间,因为我在“django 1.10”中没有找到django动态模型

这是来自github的源代码,尝试它而不是sql\u model\u create,我尝试在我的项目中取得成功,这是真的


我努力工作了很长时间,因为我在“django 1.10”中找不到django动态模型。

谢谢你的回复,但我使用的是最新的django版本1.11,在这里找不到
sql.sql\u model\u create
,我如何在1.11中实现这一点?我如何创建表,但如何在admin中注册它?我尝试了很多方法,但我无法做到这一点。你们能帮我解决这个问题吗?这对我来说太棒了。感谢advacne在views.py中创建了动态模型实例之后,您是否尝试过这个“admin.site.register(model_name)”?请详细说明,我如何在views.py中实现这一点,到目前为止,我只是在控制台中尝试。您能帮我一下吗,我如何将这些表称为html表单感谢您的回复,但我使用的是最新的django版本1.11,在这里找不到
sql.sql\u model\u create
,我如何在1.11中实现这一点?我如何创建表,但如何在admin中注册它?我尝试了很多方法,但我无法做到这一点。你们能帮我解决这个问题吗?这对我来说太棒了。感谢advacne在views.py中创建了一个动态模型实例之后,您是否尝试过这个“admin.site.register(model_name)”?请详细说明,我如何在views.py中实现这一点,到目前为止,我只是在控制台中尝试。您能帮我一下吗,我如何将这些表称为html表单
with connection.schema_editor() as editor:
        editor.create_model(Model)