0

I have CustomUser class

class CustomUser(User):
    some_extra_field = models.CharField(max_length=30, blank=True)

Now in some view I get User instance as argument and inside this view I want to create CustomUser instance based on that argument.

Should I do this like this?

def view(user):
    custom_user = user
    custom_user.__class__ = CustomUser
Nick
  • 1,134
  • 7
  • 12

1 Answers1

0

Does this question on extending the User Model help?

Community
  • 1
  • 1
Kevin London
  • 4,628
  • 1
  • 21
  • 29
  • I've read a lot of questions on stackoverflow and other sites. I decided to use model inheritance. But I didn't find an answer on my question there. – Nick Aug 09 '12 at 06:46
  • The [Django docs](https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users) linked in the discussion seem like they'd have useful code. Looks like you'll want to subclass the models.Model as you're already doing and then add additional fields. From there, the docs go into how you might instantiate your CustomUser. – Kevin London Aug 09 '12 at 06:50