如何在syncdb之后将Admin类添加到模型中?
我在 models.py 中添加了一些模型,我想添加一个管理类以在文本字段中使用所见即所得编辑器。
嗯,我知道 Django 本身不支持迁移,而且我使用过 South,但它也不起作用。
南方没有“看到”这种变化。
难道 South 只检测到字段的更改,但如果我添加新类则不会检测到?
我如何调整 Django 来检测此类更改?
I added some models in my models.py and I want to add an admin class to use a wysiwyg-editor in text-fields.
Well, I know that Django itself doesn't support migrations and I've used South, but it doesn't work either.
South doesn't "see" the change.
Could it be, that South just detects changes to fields, but not if I add a new class?
How can I tweak Django to detect such changes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
syncdb
和 South 仅关注INSTALLED_APPS
中列出的应用中Model
的后代。其他一切都由 Django 直接处理。syncdb
and South are only concerned with descendants ofModel
in apps listed inINSTALLED_APPS
. Everything else is handled by Django directly.不幸的是,你似乎很困惑。当然,Django 会读取 models.py 中的代码 - 否则它还有什么意义呢? Django 在执行syncdb 时最初使用该代码来定义模型SQL,但它不会在后续调用syncdb 时修改现有数据库表 - 因此需要South。
但自然地,Django 使用 models.py 和 admin.py 以及所有其他 Python 代码来定义自己的配置和状态。 (请注意,管理类不是在 models.py 中定义的,而是在 admin.py 中定义的。)
如果您没有看到更改,则需要重新启动服务器。
You seem to be very confused, unfortunately. Of course Django reads the code in models.py - otherwise what would be the point of it? Django uses that code initially to define the model SQL when doing syncdb, but it doesn't modify existing database tables in subsequent calls to syncdb - hence the need for South.
But naturally, Django uses models.py and admin.py and all the other Python code to define its own configuration and state. (And note that admin classes are not defined in models.py but in admin.py.)
If you are not seeing changes, you will need to restart your server.
我相当确定,如果您按照教程中概述的步骤创建管理应用程序,它就会正常工作。迁移不是问题,因为管理应用程序创建新表而不是更改现有表。
I'm fairly sure that if you follow the steps as outlined in the tutorial to create an admin app it'll just work. Migration isn't an issue as the admin app creates new tables rather than altering the existing one.