[Fixed]-Using django models across apps?

18👍

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

3👍

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.

👤lprsd

1👍

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

1👍

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.

1👍

For your specific example, I would use a Django templatetag.

Having a templatetag “display_top_meetings” in your Meetings app, and calling it with {{ display_top_meetings 5 }} from your index template, loading it first.

You can read more about templatetags here:

Django Official documentation about TemplateTags

B-List’s article on writting ‘better template tags’

I hope this help!

0👍

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

Leave a comment