Miltenyi Biotec German Living in the Netherlands Sebastian Steins (my German friends call me Seb(i), my Dutch friends call me Bas) Programming since the age of 14, Python since 2007, Django since 2008 Btw, Django is boring tech now: First release in 2005 (that was when web2.0 was a thing)
(everything below Managers and QuerySets) is undocumented and not intended to be accessed in your project. It is subject to changes (especially since the introduction of async ORM) Just be warned but hack on!
models.CharField(max_length=255) class Author(models.Model): name = models.CharField(max_length=255) class Post(models.Model): author = models.ForeignKey(Author, on_delete=...) blog = models.ForeignKey(Blog, on_delete=...) title = models.CharField(max_length=255) body = models.TextField()
def get_queryset(self): """ Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager. """ return self._queryset_class(model=self.model, using=self._db, hints=self._hints) ...
a lazy database lookup for a set of objects.""" ... @property def query(self): if self._deferred_filter: negate, args, kwargs = self._deferred_filter self._filter_or_exclude_inplace(negate, args, kwargs) self._deferred_filter = None return self._query ...
Query: ... def sql_with_params(self): """ Return the query as an SQL string and the parameters that will be substituted into the query. """ compiler = self.get_compiler(DEFAULT_DB_ALIAS) return compiler.as_sql() ...
class SQLCompiler: ... def get_select(self): """ Return three values: - a list of 3-tuples of (expression, (sql, params), alias) - a klass_info structure, - a dictionary of annotations The (sql, params) is what the expression will produce, and alias is the "AS alias" for the column (possibly None). The klass_info structure contains the following information:
does not return another QuerySet Most of these methods a special Python methods (dunder) QeurySet implements: __iter__ (e.g. for blog in qs ) __len__ (returns count of instances) __getitem__ (e.g. qs[:10] ) – implements LIMIT couple of others like __bool__ , __nonzero__