开发者

Django: Can I have an app in a sub folder of another app?

I tried to put an app inside another app (Outer one is a facade into the inner one so it made sense to locate them that way), and it doesn't create a table for the model in that inner app. Is this normal? (the app is insta开发者_运维知识库lled, and registered with the admin)


Django loads models by importing the models module of every package in the INSTALLED_APPS setting. For example, with an INSTALLED_APPS setting of ('django.contrib.admin', 'django.contrib.comments', 'spam.ham', and 'eggs'), Django will import models from django.contrib.admin.models, django.contrib.comments.models, spam.ham.models, and eggs.models.

If you are only listing your outer app in INSTALLED_APPS (we'll assume it's named eggs), then only the models from eggs.models are being imported and created. To get the models installed from your inner app, you will need to add it to the INSTALLED_APPS as well, like eggs.inner_app, so that eggs.inner_app.models will get imported. (To facilitate foreign keys, I'm pretty sure that if you import models from one app into another's models.py file, only the models defined in the models.py file being scanned get created.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜