I'd like to extend the User model, so I can put in some extra fields and functions (not only fields, keep in mind, or else (well, still) I could use get_profile(), which I think is ugly).
Also I would like to use that new extended User model in request.user, like this:
Extended User model:
# imports etc
class CustomUser(User):
extra_field = ...
def extra_function(self):
...
return ...
Example usage view:
# imports etc
def extra_function_view(request):
print request.user.username
print request.user.extra_field
request.user.extra_function()
return HttpResponse( ... )
The above code obviously doesn't work, because extra_field and extra_function are not in the User model.
Now I found a method to accomplish this, using an authentication backend, which is kinda complex, and which I couldn't get to work in Django 1.2.3.
AUTHENTICATION_BACKENDS = (
'myproject.auth_backends.CustomUserModelBackend',
)
...
CUSTOM_USER_MODEL = 'accounts.CustomUser'
Further more tried some other methods, like using signals, which didn't work. To me, the only solution seems to adjust the User model within Django (which isn't an elegant solution, adjusting Django's source code, but is code-wise a neat solution).
So I'm looking for a solution for this.. has anyone done this before?
Thanks for now
Stefan