[Fixed]-How do you actually use a reusable django app in a project?

8👍

TL;DR:

Nope & it depends…

Some (Very) Common Reusable Apps

… those are all reusable Django apps, that happen to be shipped with Django (most of them were not, at some point in time)

Ok, some other reusable apps that don’t ship with Django:

Those are all truly reusable apps, and nothing less. There are very many more apps like that.

How do they do it?

To me your question looks more like “how do I build reusable apps”, then “how to use them”. Actually using them is very different from app to app, because they do very different things. There is only one rule: RTFM No way around that either.

Often, they rely on one or more of the following:

  • additional value(s) in settings.py
  • addition (usually one include statement) to urls.py
  • subclassing and/or mixins for Models, Forms, Fields, Views etc.
  • template tags and/or filters
  • management commands

Those are all powerful ways though which your app can provide functionality to other apps. There is no recipe (AFAIK) to make a reusable app, because there are so many different scenarios to consider. It all depends on what exactly your app should do.

Reusable apps provide functionalities

I’d argue that it’s important to not think of reusable apps as “working together” with other app, but instead recognize that that they “provide functionality.” The details of the functionality provided should dictate the way the target developer is supposed to use your library.

Not everything should be reusable

Obviously enough, even though many apps can “in principle” be reusable, it often makes little sense to do so, because it is way faster to clump things together (and make them just “work together”).

👤frnhr

1👍

I’m not sure why you think you need a main app for the “frontend” stuff. The point of a reusable app is that it takes care of everything, you just add (usually) a single URL to include the urls.py of the app, plus your own templates and styling as required.

And you certainly don’t need to wrap the app’s views in your own views, unless you specifically want to override some functionality.

I don’t understand at all your question about models. There’s no such thing as a “main” models file, and using a reusable app’s models is just the same as using models from any of your own apps.

Normally you would not edit a third-party app, that would make it very hard to integrate updates. Just install the app in your virtualenv (you are using virtualenv, of course!) with pip, which will put it in the lib directory, and you can reference it just like any other app. Make sure you add it to INSTALLED_APPS.

Leave a comment