Django QuerySet - only() vs defer() vs exclude()
If you have some fields in your Django model that contain a lot of data and you don't need those fields for a particular query, you can tell Django not to retrieve them with
defer()works at the attribute level,
exclude()works on the row level.
In other words,
exclude()arguments are used after the
WHEREclause -- i.e.,
SELECT * FROM users WHERE name = 'jan'-- while
*to the provided fields -- i.e.,
SELECT name, email FROM users.
only(). If you have fewer fields that you want to retrieve than those you don't, you can use
only()to retrieve only the fields provided as arguments: