mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-11-01 16:17:25 +03:00
Django styleguide used in HackSoft projects
| README.md | ||
Django Styleguide
Django styleguide used in HackSoft projects.
Expect often updates as we discuss & decide upon different things.
Overview
In Django, business logic should live in:
- Model properties (with some exceptions).
- Model
cleanmethod for additional validations (with some exceptions). - Services - functions, that take care of code written to the database.
- Selectors - functions, that take care of code taken from the database.
In Django, business logic should not live in:
- APIs and Views.
- Serializers and Forms.
- Form tags.
- Model
savemethod.
Model properties vs selectors:
- If the model property spans multiple relations, it should better be a selector.
- If a model property, added to some list API, will cause
N + 1problem that cannot be easily solved withselect_related, it should better be a selector.