Skip to content

Query DRY Engine [Experimental]

Giuseppe Novielli edited this page Jul 13, 2024 · 2 revisions

Overview

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)

Rule

  1. Every Model must have at least one Manager.

  2. QuerySet class (use QuerySet class) is stored into querysets.py file. Into QuerySet class write ALL queries.

  3. Manager class (use QuerySet as base class, created into step 2) is stored into managers.py file.

  4. For each model's field write a Single Method

  5. Every method MUST HAVE ONE filter, referenced by manager model.

  6. Use Subquery to join into another table

Method Naming

  1. Single model field: <name_field>
  2. App model Subquery: <name_model>__<method subquery name>
  3. External app model Subquery: <name_app>___<name_model>__<method subquery name>
  4. Multiple method call: <method1>___<method2>___<method3>
  5. Subquery Multiple method call: <name_model>__<method subquery name1>___<method subquery name2>
Clone this wiki locally