Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

django

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 installed, and registered with the admin)

like image 506
orokusaki Avatar asked Jan 07 '10 07:01

orokusaki


1 Answers

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.)

like image 69
LeafStorm Avatar answered Oct 15 '22 17:10

LeafStorm