views:

374

answers:

5

So in my Django project I have a few different apps, each with their own Models, Views, Templates, etc. What is a good way (the "Django" way) to have these Apps communicate?

A specific example would be a Meetings App which has a model for Meetings, and I have a Home App in which I want to display top 5 Meetings on the home page.

Should the Home App's View just query the Meetings App's Model?

It feels like that is crossing some line and there might be a more de-coupled way to do things like this in Django.

Any help is much appreciated!

+4  A: 

At some point your apps will have to couple in order to get any work done. You can't get around that.

Ignacio Vazquez-Abrams
Yeah I kinda figured. Thanks.
Ryan Montgomery
A: 

Should the Home App's View just query the Meetings App's Model?

Yep, that's how it's done. If you really want to decouple things, you could make your Home app use generic foreign keys, and some sort of generic template system, but there's not really a good reason to, unless you have grand plans for your home app being pluggable and working with a bunch of other different Django apps.

Writing tightly coupled Django apps is really easy, and writing decoupled Django apps is really hard. Don't decouple unless you have a reason to, and you'll save yourself a lot of work (and happiness!).

ShZ
"Writing tightly coupled Django apps is really easy, and writing decoupled Django apps is really hard" -- I hear what you are saying here... "Don't decouple unless you have a reason to, and you'll save yourself a lot of work" - Doesn't this go against the sound software engineering principles of keeping systems as loosely coupled (in the first place) as possible?
Frank V
A: 

yes. I think thats a design feature. All models share a backend, so you'd have to do extra work to have two models with the same name in different apps.

Projects should not share Models

George
+1  A: 

If it were me, I would make a template tag in your meeting app that produces the desired output and include that template tag in the home app's template.

That way you are only coupling them in the View portion of the MVC and makes it easier to maintain if you change your models in the meeting app.

Steven Potter
A: 

To achieve decoupling as much as possible,

You need to have a Project specific app, that does all the hooking up things between each other.

Using signals from models to create new models in a decoupled apps helps. But doing too much of this, is foolish.

Lakshman Prasad