Reputation: 37876
I am now working on a big django project.
Huge topicportal with many topiccenters and book and other media profiles and author profiles and normal user profiles who can also have author profiles..
Now what i do is:
One django app, templates folder as usual and now number of templates is becoming huge as i create templates ..
I have never experienced to have multiple apps in one project..
Can someone please tell me if thats what i am doing is ok or if i should go for multiple apps ?
Or if i put in different way: when does it make sense to have multiple apps in one project?
Thanks in advance
Upvotes: 0
Views: 245
Reputation: 680
You can have core apps which don't depend on others apps (most likely it will be something like)
and "Application" apps which use the above
A nice structure to start with is a template from "Two Scoops of Django" https://github.com/twoscoops/django-twoscoops-project
"thank you, very nice guidance. I was wondering because all models are in relation, dont i destroy the relation if i separate them into multiple apps? "
You should be able to divide the models across apps - read:
Define ManyToMany relation in another application in Django
Django relationships between apps: How to keep apps separate?
Upvotes: 1
Reputation: 1994
Django is made to thrive on having multiple apps. 1 App for user signup, 1 app for profiles, 1 app for comments, 1 app for blog postings, etc. etc.
Doing everything in one app will, as you pointed out, quickly lead to clutter. The best method with Django is to create many very specific applications. This also allows you to have more apps that you can reuse in other projects if you so wish.
There are dozens of possible "structures" for a Django project. I'd go for the most modular approach. And for every piece of functionality just ask yourself: Does this belong directly to another app? If the answer is no you're most likely better of creating a separate app for it.
E.g the same blog postings app can be used on multiple websites and you'd only have to change the template to make it fit the new layout/design of the page. All the logic should be mostly the same. And the logic of a blog post should not be linked to the logic of viewing a profile or something.
Example: for a comment app the model could look like this:
from django.db import models
from profile.models import Profile
from blog.models import Blog
class Comment(models.Model):
user = models.ForeignKey(Profile, related_name='comments')
blog = models.ForeignKey(Blog, related_name='comments')
message = models.CharField(max_length=200)
Upvotes: 2