I have seen that queries like :
user = User.objects.all() or User.objects.filter(username = username)
will fetch all the columns of the table even if we do not need all the columns. Do we have a better way of writing a database query? and if yes why do we not see that code most often?
QuerySet.only()andQuerySet.defer()can be used to refine which fields the ORM will pull, deferring the others until the appropriate attributes on the models are accessed.