0

I want the exact same behaviour as django.contrib.auth.User but I need to extend the model with some user preferences and profile specific fields.

I know I could eventually make two new models which could be

class Profile(models.Model):
    user = OneToOneField(User)
    age = SmallPositiveIntegerField()

and

class Preference(models.Model):
    user = OneToOneField(User)
    background_color = CharField(max_length=6)

I don't know if it's smart to separate these things.

But I want to retrieve the user preferences on each page and if I use this approach by extending the User model with an OneToOneField it costs another sql query for each time I get user.preference.background_color.

I think it might be overkill to substitute the User model (or what) so what can I do?

Will proxy models be the answer?

1

1 Answer 1

1

The way people (Two Scoops, for example) generally recommend doing this is by subclassing AbstractUser (or AbstractBaseUser if you want even fewer of the base user fields; baseuser just gives you password, login timestamp, and is_active). You'd then just add fields as you would for a normal model and query them as you would for a normal model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.