In this great talk by James Bennet (at about 20mins 30s) he discusses breaking up your site into lots of small reusable django apps:
https://youtu.be/A-S0tqpPga4?t=1228
He talks about how to separated out a contact form into its own Django App. This sounds great. He mentions you can pass in your own Form to customise the sign up application.
What I don’t understand though, is that often the model is the central point/foundation of an app. And if one is passing in a different form that has different fields, then that form must be linked to a different model.
Where does that model live in this reusable app architecture? If the model lives outside the app, its hard to imagine coding an app without the Django encouragement of “fat models”?
I have tried creating reusable apps in the past, buy always get tripped up by the models. How to customise then slightly for each use case. I then try to use this pattern (which is not great, but the best I came up with):
- You write a Mixin that contains the extra fields you want. In this example of the sign up form, the mixin could have an extra field say
favourite_color
. - The Signup form uses this mixin to add the extra fields to its own model
- You then import/can use this Signup Model class.
Later James talks about get_model
. Is there a matching put_model
? I.e. if we are going to load a sign up form model from somewhere else, how do we specify where that somewhere else is? Maybe I am thinking about it wrong. But get_model
is supposed to be a more dynamic way of getting a model, which means there must be a dynamic way of assigning models from a diff app to another app. In this case I am guessing I would specify my own sign up model in my own app, then somehow tell django this is the sign up model to be used by the sign up app?