Go – Django: use custom class for request.user

django

I've extended Django's default user class like this:

class CustomUser(User):
    friends = models.ManyToManyField('self', symmetrical=False)

But now I want to use that everywhere instead of the default User class. In my view methods, I have access to request.user but that's an instance of the User class. What's the easiest way to make it return a CustomUser instead?

Best Answer

you can also "monkey patch" the existing User model somewhere in your models.py and it should just work. In your code just keep using the original class.

User.add_to_class('friends',models.ManyToManyField('self', symmetrical=False))
Related Topic