I have been working a while on a Django project which has been growing a bit lately. I have been think a bit about what strategy to use to make it easier to handle. One thing I would like to get some input on would be if I should split my application into several smaller applications. That would make my view and model files smaller and separate some of the concerns.
One thing that bothers me with this is that in my applications I would have several helper methods that will be used across applications. Also some models will also have to be shared/used across applications. Would this make sense? This doesn’t go well with the separation of concerns I was hoping to achieve by splitting my app in several smaller apps.
What would be a good approach for sharing helper methods, models etc. across applications?
0
If your project is getting large, think of apps as reusable modules. You can separate out the functionality that is shared across your apps into its own app.
See the discussions below for more thoughts on the matter:
- When to create a new app (with startapp) in
Django? - What is a Django “app” supposed to
mean? - What is an “app” in
Django?
1
I like to create a base/
app with no views and no moments for shared stuff.
One problem that can occur when you have models spread over multiple apps is circular imports. This can be avoided by using strings to refer to other models (foo = ForeignKey("someapp.Foo")
instead of foo = ForeignKey(someapp.models.Foo)
). Django lets you use strings like this in more places.