Because:
-
You moved everything out of the
views.py
modules when you heard fat controllers were bad. -
And you’ve read that fat models are a good idea1.
-
You need some extra functionality in a template and this is the easiest way to shoehorn it in. Eg:
<p> The current balance is {{ account.get_balance_via_three_network_calls_lol }} </p>
-
You can quickly solve your current problem by adding n more lines to that method (repeat ad infinitum)2.
-
You’re scared people will ignore your crucial wrapper function if it’s not directly on the model3.
-
Are you even allowed to put application logic anywhere but a
models.py
?4
-
For example:
- Fat Models - A Django Code Organization Strategy
- Django Best Practices: Make ’em Fat
- Ultimate Django: Adding Business Logic to Models However, in practice, they’re a bad idea (although this sometimes takes a few months to become apparent).
-
Requires a poor-quality test suite and diligent ignorance of the Single Responsibility Principle. ↩︎
-
A legitimate problem with a liberal language like Python where it’s hard to enforce calling conventions as nothing is truly private. ↩︎
-
You are: your web framework is not your boss. As a rule-of-thumb, your application logic should live in modules that aren’t Django-specific modules (eg not in
views.py
,models.py
orforms.py
). If I had my way, Django would create an emptybusiness_logic.py
in each new app to encourage this. ↩︎