class MyUser(User):
job = ...
city = ....
MyUser.objects.get(pk=request.user)
and MyUser.objects.get(pk=request.user.id)
give me the same result. From doc, pk must be an int. But request.user is an object. Why queries are the same for object and user id?
edit : I know that request.user is object but I want to know why results are same.
Thanks in advance
This is by design - if you pass a model object as the parameter to a query, it is the same as passing its primary key.
If this wasn't the behaviour, either passing the pk would be required, or an error, which would merely be annoying.
Thanks to rebus for this reference to the source: https://code.djangoproject.com/browser/django/trunk/django/db/models/fields/related.py#L175
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