pyknight202
pyknight202

Reputation: 1497

Separate foreign-key linked model or a custom user model for User Settings in Django?

Would it be more efficient to create a custom user model if I want settings to be tied to the user (AbstractUser would be used)?

The other seemingly simpler option would be to create a Settings model in my main app and tie it to the user with a foreign key. Which would be more maintainable when the user-base grows?

Some examples of a few settings options would be private profile, hidden in search, profile pictures.

Upvotes: 0

Views: 45

Answers (1)

Jorge Mauro
Jorge Mauro

Reputation: 383

1. Create a Custom User Model:

You should create a custom User Model extending AbstractUser when you use Django authentication process and need to add some extra information directly in the User model, without having to create another class.


2. Create a Settings Model in my main App and tie it to the User Model with a OneToOneField:

You should use a One-To-One Link as long as you have to store extra information about the existing User Model and it doesn't have anything to do with the authentication process.


Reference: https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html

Upvotes: 1

Related Questions