Add a method to Django's User class
Extending the Django User is a bit of a pain for the moment. Of course you have the profile option, but I just needed to have a method deactivating an user by setting its "is_active" field to False and recording some stuff with that.
Sure it could have gone in a view, but the challenge of overriding the User class was too good to pass so here we go:
from django.contrib.auth.models import User
class UserFunctions:
def deactivate(self):
self.is_active = False
...
User.__bases__ += (UserFunctions,)
And boom ! Now you can simply use the method like a boss.
Written by Adrien F
Related protips
1 Response
Monkey-patching. No way.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#