I have a project that I wrote in PHP/symfony that uses 45 tables. I'm in the process of porting it to Python/Django.
There's a belief I've held for years that you should split up your projects into a bunch of small files rather than a few huge files. From what I understand, that's not an odd thing to believe. In Rails and symfony, there's a one-model-per-file convention. In Django, however, it seems that most developers put all of each app's models in one file.
This makes sense to me if your apps are each small enough. It doesn't make sense to me for large apps, though, and what I have is at least one large app.
Out of the 45 tables my project uses, 35 are closely related. I have a script that imports data from CSV files. For each line in each CSV file, I save 50-80 pieces of data into 30-35 different tables in one fell swoop.
Maybe I'm just thinking about this the wrong way but it would seem incredibly odd to me to divide my project into 6 or 7 different apps when almost all my tables are inextricably linked. When I touch one table, I touch all 35 tables. The delineations would have to be arbitrary. What would be the point of that?
Please forgive me if I come off as biased because I certainly am biased. I'm not having this problem in symfony and I wouldn't be having it in Rails. (I chose Django because of GeoDjango and Python's GIS capabilities.)
What should I do?
Any app can use any other app's code, including models. And you can have as many models as you like in a single app.
Django comes with six built-in apps that we can examine.
A project refers to the entire application and all its parts. An app refers to a submodule of the project. It's self-sufficient and not intertwined with the other apps in the project such that, in theory, you could pick it up and plop it down into another project without any modification.
If having one model per file would be the perfect answer for you, there's an app for that.
I've never done it on a scale of 80 model files but I can certainly point you towards another stack question:
About 20 models in 1 django app
http://djangosnippets.org/snippets/1838/
What kind of circular reference problems are you having by the way? If it's with ForeignKey definitions, here's a way around that... http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey
You can also look into django.db.loading.get_model
, but some may frown on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With