ฉันกำลังพยายามแยก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
วิธีนี้ใช้ไม่ได้ผลฉันพบสิ่งนี้แต่ในโซลูชันนี้ฉันยังคงมีปัญหาเมื่อฉันเรียกใช้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;
ฉันไม่ค่อยแน่ใจเกี่ยวกับเรื่องนี้ แต่ฉันกังวลเกี่ยวกับส่วนนี้ 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"
ดังนั้นฉันควรเรียกใช้การเปลี่ยนแปลงสำหรับการอ้างอิงด้วยตนเองหรือไม่? นี่อาจทำให้ฉันมีปัญหากับทิศใต้?
from app1.models.model1 import Store?