WRITELOOP

DJANGO - MANAGERS AND QUERYSETS

2020 November 12
  • For simple queries use managers, for complex ones use querysets.

  • manager:

    • Facade for operations on the data storage
    • Delegate performing the queries to querysets
    • Could be used as “repositories”
    • Interface that provides query operations to models (CRUD on the tables)
  • querysets:

    • “final frontier between the domain and the raw data storage”
    • Implement the “Query Object Pattern” by Martin Fowler
    • Allow building queries with python objects
    • whenever you need to customize how an SQL will be built or its response, querysets are where that it must be done.
    • Queries are made using “lazy loading”
NOTE: The original content(s) that inspired this one can be found at:
https://medium.com/@jairvercosa/manger-vs-query-sets-in-django-e9af7ed744e0
All copyright and intellectual property of each one belongs to its' original author.