If I use the get()
function to get one item from the model, I cannot use select_related()
, as that object doesn't have it, but I'd still like to use it to save myself one DB query. What I'm saying is that this doesn't work (and I'd like it to):
MyModel.objects.get(id=100).select_related('related_model')
What I can do is not what was intended. I can do this:
MyModel.objects.filter(id=100).select_related('related_model')[0]
But it's not the same. Can I do something about it?
I think
MyModel.objects.select_related('related_model').get(id=100)
works, but I can't test it right now.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments