J'essaie de diviser le models.py
de mon application en plusieurs fichiers :
J'ai d'abord pensé qu'il fallait faire cela :
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
Cela ne fonctionne pas, puis j'ai trouvé este Mais dans cette solution, j'ai toujours un problème, lorsque je lance python manage.py sqlall app1
J'ai obtenu quelque chose comme :
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;
Je ne suis pas très sûr de moi, mais je suis inquiet pour cette partie. The following references should be added but depend on non-existent tables:
Voici mon fichier model1.py :
from django.db import models
class Store(models.Model):
class Meta:
app_label = "store"
Voici mon fichier 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"
Apparemment, cela fonctionne, mais j'ai reçu le commentaire suivant alter table
et si j'essaie ceci, la même chose se produit :
class Product(models.Model):
store = models.ForeignKey('store.Store')
class Meta:
app_label = "product"
Dois-je donc lancer manuellement le programme alter pour les références ? Cela risque-t-il de me poser des problèmes avec South ?