我试图分裂我的应用程序的models.py
成几个文件:拆分models.py分成几个文件
我的第一个猜测是这样:
myproject/
settings.py
manage.py
urls.py
__init__.py
app1/
views.py
__init__.py
models/
__init__.py
model1.py
model2.py
app2/
views.py
__init__.py
models/
__init__.py
model3.py
model4.py
这不起作用,那么我发现this,但在这种解决方案我仍然有一个问题,当我运行python manage.py sqlall app1
我有一样的东西:
BEGIN;
CREATE TABLE "product_product" (
"id" serial NOT NULL PRIMARY KEY,
"store_id" integer NOT NULL
)
;
-- The following references should be added but depend on non-existent tables:
-- ALTER TABLE "product_product" ADD CONSTRAINT "store_id_refs_id_3e117eef" FOREIGN KEY ("store_id") REFERENCES "store_store" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "product_product_store_id" ON "product_product" ("store_id");
COMMIT;
我不是很肯定这一点,但我很担心一个boout部分The following references should be added but depend on non-existent tables:
这是我model1.py文件:
from django.db import models
class Store(models.Model):
class Meta:
app_label = "store"
这是我model3.py文件:
from django.db import models
from store.models import Store
class Product(models.Model):
store = models.ForeignKey(Store)
class Meta:
app_label = "product"
而且很显然工作,但我在alter table
,如果得到了评论我试试这个,发生同样的事情:
class Product(models.Model):
store = models.ForeignKey('store.Store')
class Meta:
app_label = "product"
所以,应该我手动运行修改引用?这可能会带给我南方的问题吗?
如果您尝试从“app1.models.model1 import store'?模型3中会发生什么? – 2011-06-14 00:31:39
此外,你可能想要检查http://stackoverflow.com/questions/5534206/how-do-i-separate-my-models-out-in-django/5534251#5534251 – 2011-06-14 00:33:26