Django: use custom class for request.user?

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))

I'm not sure if you can do that exactly, but you can access your CustomUser attributes using the Django user_profile feature.

In your settings.py:

AUTH_PROFILE_MODULE = 'myapp.CustomUser'

In your view:

user_friends = user.get_profile().friends

Check out this link for more info.


It is all explained here. request.user problem was solved by using an authentication backend. I implemented a custom user according to the author's instructions and have been happy ever since.

Tags:

Django