0๐
โ
tgdn helped me realize that I was doing something really dumb: I was trying to filter down to a specific user in get_queryset()
when I should have been returning all users.
I was able to get things working like this:
# Update a User
class DisableCompanyUserView(UpdateAPIView):
model = User
serializer_class = UserSerializer
lookup_url_kwarg = 'user_id'
def get_queryset(self):
return User.objects.all()
def partial_update(self, request, *args, **kwargs):
kwargs['partial'] = True
return self.update(request, *args, **kwargs)
Which I simplified down to this:
# Update a User
class DisableCompanyUserView(UpdateAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
lookup_url_kwarg = 'user_id'
def partial_update(self, request, *args, **kwargs):
kwargs['partial'] = True
return self.update(request, *args, **kwargs)
๐คIAmKale
1๐
And if you try looking it up with
User.objects.get(id=theId)
Does that return any object?
pk
is only a short form of id__iexact
EDIT
Have you tried manually doing
User.objects.filter(pk=yourID)[0]
This should get you results. Otherwise, try
User.objects.all()
And look if you can find the user you are looking for
- [Answer]-Join a table without creating a foreign key or add objects that break foreign key relationship?
- [Answer]-Can I link Django permissions to a model class instead of User instances?
- [Answer]-How to use models associated with a user in Django when rendering an HTML page
- [Answer]-Django โ Legacy MySQL data migration errors
Source:stackexchange.com