mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2025-02-06 22:50:53 +03:00
Add first draft for Overview
This commit is contained in:
parent
ac4f07f8c6
commit
3cb761831a
28
README.md
28
README.md
|
@ -1,2 +1,26 @@
|
||||||
# Django-Styleguide
|
# Django Styleguide
|
||||||
Django styleguide used in HackSoft projects
|
|
||||||
|
Django styleguide used in [HackSoft](https://hacksoft.io) 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 `clean` method 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 `save` method.
|
||||||
|
|
||||||
|
**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 + 1` problem that cannot be easily solved with `select_related`, it should better be a selector.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user