S
S
svolosch2017-02-10 16:08:51
Django
svolosch, 2017-02-10 16:08:51

Is it worth it to extend the User model in Django like this?

Good afternoon.
I am learning Django. The question is more of an academic character...
I want to make email as a login. There are batteries and other things on the Internet, you are interested in doing it yourself. At this stage, I do not need additional information for the User
. Should I go this route?
1. Extend the model through the proxy Meta class.
2. Redefine the save method, where I will assign email to username
3. Register your model in AUTH_USER_MODEL Later
, it seems to me, it will be possible to expand, if necessary, the model through an additional table and OneToOneField.
What am I right/wrong about?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artyom Innokentiev, 2017-02-10
@artinnok

The save method to override is the most edge, last resort, and in general, bad practice.
Model proxies are usually used when extending an existing model - adding methods, properties or changing the manager, but not affecting the attributes.
It is the most difficult to write your own model, but this is the most flexible and controllable option. And it's good to be able to write your own user model, depending on the task.

E
Evgeny Maltsev, 2017-02-11
@hellpirat

https://docs.djangoproject.com/en/1.10/topics/auth...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question