In rest framework exists some way to use session user instead pk and self.get_object()
in a @detail_route
view?
I want to use request.user
and don't send pk in the url.
Or maybe use another decorator instead @detail_route
...
It's hard to tell what you're trying to archive in the first place. Maybe it's easier to use a separate view instead of the viewset action this case? For example here is a view snippet that lets currently logged in user manage his account:
class CurrentUser(generics.RetrieveUpdateDestroyAPIView):
serializer_class = UserSerializer
def get_object(self):
return self.request.user
def perform_destroy(self, instance):
instance.is_active = False
instance.save()
Add this to your urlpatterns
without pk
in the pattern:
url(r'^users/me/$', CurrentUser.as_view()),
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