开发者

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

开发者 https://www.devze.com 2022-12-15 21:09 出处:网络
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 no

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

精彩评论

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