These are chat archives for wronglink/django-rest-framework

14th
Nov 2016
sukianto
@sukianto
Nov 14 2016 13:01
Hi, I'm using django rest framework and django-rest-auth for login
But django-rest-auth can't detect is_staff
So I copy-paste the code to my views and add some code, I think that's not good cause repeating the code, is there any proper way to do this?
JohnnyBDude
@JohnnyBDude
Nov 14 2016 13:07
Try subclassing the rest-auth views, overriding yout methods And calling super to call implementation from superclass:) That might do the job
Sorrz for thr quick answer, i am writing from mobile And i am in quitr ahurry
sukianto
@sukianto
Nov 14 2016 13:09
Ok, thanks will search about it, no problem
thanks so much :)
JohnnyBDude
@JohnnyBDude
Nov 14 2016 13:11
You Re welcome. Just write if you get stuck.
sukianto
@sukianto
Nov 14 2016 13:15
Ok :+1:
sukianto
@sukianto
Nov 14 2016 13:41
Wow, that's very nice, sorry I'm very basic on this so need confirmation, is my code good?
import rest_auth.registration.views
class AdminLogin(rest_auth.registration.views.LoginView):
    """Admin login"""
    def post(self, request, *args, **kwargs):
        user = authenticate(
            email=self.request.data["email"],
            password=self.request.data["password"]
        )
        if not user.is_staff:
            msg = 'User account is not staff.'
            raise exceptions.ValidationError(msg)

        super(AdminLogin, self).post(request, *args, **kwargs)

        return self.get_response()
but don't texting on drive