Reputation: 14317
According to Django documentation if a field is trying to be reached in raw query set, it would fetch it in real time.
How can I prevent it from fetching fields not being retrieved from the database?
e.g. if I write select name from authors
and later a user will write author.gender it would return None and not attempt to retrieve it from the database?
Upvotes: 0
Views: 223
Reputation: 308889
You could try fetching null
for any fields that you do not want to be retrieved, for example:
Person.objects.raw('SELECT id, name, null AS gender from authors')
Upvotes: 1