I'm currently working on a django project. I'm not completly new in django, but have some difficulties figuring out how would be the most 'djangonic' way to organize some files.
I have some classe that compute stuff, and can be used from the manage.py's cli, and by a webservice app. Those computation uses models from my core app and make call to the database.
The problem I face is that I can't figure where to put those source file.
I do not want to put them in a 'lib' folder. I think the modules in this folder will be django independent modules.
For the moment, the module is in the model of my app. But since it doesn't define any new structure, I don't think it is the cleanest way.
Any ideo to have a clean structure that respect the 'django way of life' ?
Thanks
The thing is, the most "djangonic" way of doing this is not to have a "core app" at all. You should strive to split the functionality into separate apps. I'm perfectly aware that this is not always trivial.
But let's say you are designing an intranet website for a school. You would have one app that deals with students' accounts, and another app generating timetables, and yet another one for an internal message board, etc. Every app defines its own models (there are no "project level models"), but apps can import each others models (so message board posts can have a ForeignKey field pointing at student from the "students" app). There is no need for a "main" or "core" app (see also: James Bennett's "writing reusable Django applications" presentation from DjangoCon)
You would then put your management commands in management/commands
directory of an app that the commands deal with. For example if a command removes old students from the db it would go into management/commands
inside the students
app.
If the module is independent from Django, then it should be a standalone Python package, complete with a setup.py
to install it. The Django models and webservices that use it can import like any other external dependencies.
If the module depends on you Django app, then it should be inside the app's directory. If it doesn't define new models, then it should not be in models.py
.
Does this answer your question?
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