通过 app_label 在子目录中建模? [英] Model in sub-directory via app_label?
问题描述
为了将我的模型放在子文件夹中,我尝试使用描述的 app_label Meta 字段 这里.
In order to place my models in sub-folders I tried to use the app_label Meta field as described here.
我的目录结构如下:
- 项目
- 应用
- 富
- 模型
- __init__.py
- bar_model.py
在 bar_model.py 中,我像这样定义我的模型:
In bar_model.py I define my Model like this:
from django.db import models class SomeModel(models.Model): field = models.TextField() class Meta: app_label = "foo"
我可以像这样成功导入模型:
I can successfully import the model like so:
from apps.foo.models.bar_model import SomeModel
但是,运行:
./manage.py syncdb
不为模型创建表.然而,在详细模式下,我确实看到了应用程序foo"被正确识别(它位于 settings.py 的 INSTALLED_APPS 中).将模型移动到 foo 下的 models.py 确实有效.
does not create the table for the model. In verbose mode I do see, however, that the app "foo" is properly recognized (it's in INSTALLED_APPS in settings.py). Moving the model to models.py under foo does work.
是否有一些特定的约定没有在 app_label 或整个机制中记录,以防止该模型结构被同步数据库识别?
Is there some specific convention not documented with app_label or with the whole mechanism that prevents this model structure from being recognized by syncdb?
推荐答案
查看 Django 票证 #10985:解释如何模型可以组织在一个目录中
See Django ticket #10985: Explain how models can be organised in a directory
可能是您没有将模型导入
__init__.py
?It may be that you aren't importing your models into
__init__.py
?这篇关于通过 app_label 在子目录中建模?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 模型
- 富
- 应用