-
Notifications
You must be signed in to change notification settings - Fork 1
Query DRY Engine [Experimental]
Giuseppe Novielli edited this page Jul 13, 2024
·
2 revisions
Manger Query Engine use QuerySet to store any query associated to a Model.
- Use into every part of your project
- One place to store queries (DRY Design)
-
QuerySet class (use QuerySet class) is stored into querysets.py file. Into QuerySet class write ALL queries.
-
Manager class (use QuerySet as base class, created into step 2) is stored into managers.py file.
-
For each model's field write a Single Method
-
Every method MUST HAVE ONE filter, referenced by manager model.
-
Use Subquery to join into another table
-
Single model field:
<name_field>
-
App model Subquery:
<name_model>__<method subquery name>
-
External app model Subquery:
<name_app>___<name_model>__<method subquery name>
- Multiple method call:
<method1>___<method2>___<method3>
- Subquery Multiple method call:
<name_model>__<method subquery name1>___<method subquery name2>