tags:

views:

1166

answers:

5

I've googled around for this, but I still have trouble relating to what Django defines as "apps".

Should I create a new app for each piece of functionality in a site, even though it uses models from the main project?

Do you guys have good rule of thumb of when to split off a new app, and when to keep functionality together with the "main project" or other apps?

A: 

I tend to create new applications for each logically separate set of models. e.g.:

  • User Profiles
  • Forum Posts
  • Blog posts
pobk
+2  A: 

I prefer to think of Django applications as reusable modules or components than as "applications".

This helps me encapsulate and decouple certain features from one another, improving re-usability should I decide to share a particular "app" with the community at large, and maintainability.

My general approach is to bucket up specific features or feature sets into "apps" as though I were going to release them publicly. The hard part here is figuring out how big each bucket is.

A good trick I use is to imagine how my apps would be used if they were released publicly. This often encourages me to shrink the buckets and more clearly define its "purpose".

blahspam
+8  A: 

James Bennett has a wonderful set of slides on how to organized reusable apps.

Antti Rasinen
A: 

An 'app' could be many different things, it all really comes down to taste. For example, let's say you are building a blog. Your app could be the entire blog, or you could have an 'admin' app, a 'site' app for all of the public views, an 'rss' app, a 'services' app so developers can interface with the blog in their own ways, etc.

I personally would make the blog itself the app, and break out the functionality within it. The blog could then be reused rather easily in other websites.

The nice thing about Django is that it will recognize any models.py file within any level of your directory tree as a file containing Django models. So breaking your functionality out into smaller 'sub apps' within an 'app' itself won't make anything more difficult.

wbowers
+1  A: 

The rule I follow is it should be a new app if I want to reuse the functionality in a different project.

If it needs deep understanding of the models in your project, it's probably more cohesive to stick it with the models.

Ryan