M
M
maxclax2014-12-13 01:23:38
Django
maxclax, 2014-12-13 01:23:38

Django, how to extend a user?

Here's the code I'm trying to get new fields for the person:

class UserProfile(User):
    class Meta:
        db_table = 'users'

    discount = models.FloatField(default=0)
    is_add_review = models.BooleanField(default=False)

    objects = UserManager()

For forms and everything else it works, but there is a problem with syncdb. At startup, I created a users table and there is only one user_ptr_id field in it, and then a dead end. Tell me what am I doing wrong? How can I add fields to a person?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2014-12-13
@maxclax

Why is this all? Up to 1.5 you create a profile

class UserProfile(models.Model):
    user = models.OneToOneField(User)

and register in settings.py
From 1.5, create your own user class completely or inherit from User and register in settings.py
AUTH_USER_MODEL = 'myapp.MyUser'

V
Vladislav, 2014-12-13
@RGV

If you only need to add fields to an existing user model, then you can create OneToOneField.
Read more here: https://docs.djangoproject.com/en/dev/topics/auth/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question