In the real world, how often do people use QuerySet methods like defer()
and only()
? I guess I handnt really heard much about them and only recently have I came across these methods.
See Docs here. https://docs.djangoproject.com/en/dev/ref/models/querysets/
defer() and only() are somewhat opposite of each other. Both receives list of field_names . defer() will not query, list of columns, passed to it as argument. On Contrary to it, only() will query, only list of columns, passed to it as argument. Both are used in a scenario, where.
A QuerySet is a collection of data from a database. A QuerySet is built up as a list of objects. QuerySets makes it easier to get the data you actually need, by allowing you to filter and order the data.
This is because a Django QuerySet is a lazy object. It contains all of the information it needs to populate itself from the database, but will not actually do so until the information is needed.
These methods are mostly of use when optimizing performance of your application.
Generally speaking, if you are not having performance problems, you don't need to optimize. And if you don't need to optimize, you don't need these functions. This is a case with a lot of advanced QuerySet
features, such as select_related
or prefetch_related
.
As for "how often they are used in the real world", that isn't really an answerable question. They are used when they're needed. If you don't need them, don't use them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With