Is a Custom User Model worth the headache?

66 views
Skip to first unread message

bnmng

unread,
Feb 12, 2020, 6:47:54 AM2/12/20
to Django users
Hi.  

I read the part where it's "highly recommended" to create a custom user model, but I don't see why it's worth the headache.  I found these problems:

1 In the admin panel, my auth groups are in a separate app from my users
2 There is some disagreement out there about how apps should refer to a user model now that the user model might be custom
3 A lot of features that I would add are app specific, and therefore would be better handled by app specific profiles
4 There's a new entry point for possible errors and glitches

So why do this? 

Thanks,
Ben 

SikoraD

unread,
Feb 13, 2020, 8:04:18 AM2/13/20
to Django users
Hi Ben,

I'll highly recommended to read fantastic post on Will Vincent blog -> https://wsvincent.com/django-tips-custom-user-model/
His approach is much easier than one on django website and it is worth to have look.

Also his djangox repo on github is very useful.

Best Regards
Damian

bnmng

unread,
Feb 13, 2020, 10:30:37 AM2/13/20
to Django users
Thanks for the reply.  That is a good post and I'll go along with the recommendation, though I still don't completely understand why adding a profile isn't as good as creating a custom user, and I wish I could figure out how to group custom users and auth groups together in the same admin section

Ben 

maninder singh Kumar

unread,
Feb 13, 2020, 12:02:06 PM2/13/20
to django...@googlegroups.com
Here's my opinion on this :
1. It requires the.user model to be the first migration
2.  You could either want to extend or customise the User model
3.  If extending is all you want then use the default authentication

I tried customising it didn't find it worth my time

Willy

Sent from my iPad
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3210d917-e796-4b26-a316-fc3974bcfc0b%40googlegroups.com.

Mike Dewhirst

unread,
Feb 14, 2020, 3:05:08 AM2/14/20
to django...@googlegroups.com
I agree. The custom user will be essential for you one day and the pain
of retrofitting it is hard.

I have done a retrofit and don't recommend it unless you have no other
choice.

Definitely start a new project with a custom user and I would consider
aborting an existing project to restart with a custom user if it was
started with the standard user.

Good luck

Mike

On 13/02/2020 9:08 pm, SikoraD wrote:
> Hi Ben,
>
> I'll highly recommended to read fantastic post on Will Vincent
> <https://wsvincent.com/> blog ->
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3b3d9cbf-4637-4d77-9cd4-94f12098debe%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3b3d9cbf-4637-4d77-9cd4-94f12098debe%40googlegroups.com?utm_medium=email&utm_source=footer>.

Carsten Fuchs

unread,
Feb 14, 2020, 3:34:10 AM2/14/20
to django...@googlegroups.com
Am 14.02.20 um 09:03 schrieb Mike Dewhirst:
> Definitely start a new project with a custom user and I would consider aborting an existing project to restart with a custom user if it was started with the standard user.

Which may not be possible for large, existing projects.

Switching to a custom user model in mid-project is possible. Based on the work of other's, I've tried to summarize the required steps, see https://code.djangoproject.com/ticket/25313#comment:18 for details.

For new projects, consider https://django-improved-user.readthedocs.io/en/latest/ (rationale: https://django-improved-user.readthedocs.io/en/latest/rationale.html )

Best regards
Carsten

maninder singh Kumar

unread,
Feb 14, 2020, 9:20:11 AM2/14/20
to django...@googlegroups.com
It really depends on what you want to do with your user authentication

Sent from my iPad
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aabf51c-aa69-5210-d2c1-252173f012d6%40cafu.de.

Mike Dewhirst

unread,
Feb 14, 2020, 5:31:24 PM2/14/20
to django...@googlegroups.com
Well documented Carsten!!! Many thanks. Also, I really liked
django-improved-user and was able (having endured the retro-fitting
pain) to adjust last_name/first_name to full_name/short_name. That was
an immediate payoff.

In your documentation you mention "from accounts.models import User"

I have been maybe taking things too literally. After migrating to my
custom user I have used "from django.contrib.auth import get_user_model"
followed by "User = get_user_model"

I much prefer your direct route. Is it correct?

Thanks

Mike


Carsten Fuchs

unread,
Feb 15, 2020, 7:34:48 AM2/15/20
to django...@googlegroups.com
Hi Mike,

Am 2020-02-14 um 23:30 schrieb Mike Dewhirst:
> In your documentation you mention "from accounts.models import User"
>
> I have been maybe taking things too literally. After migrating to my custom user I have used "from django.contrib.auth import get_user_model" followed by "User = get_user_model"
>
> I much prefer your direct route. Is it correct?

Yes, I think so. As I wrote near the top, every code that is to be used by others must use the generic referencing method, so that it can deal with whatever User model the client code uses.

In your project apps that are not intended for reuse by other "foreign" code, there is, imho, no need to use the additional redirection that the generic referencing methods bring. You can just import your custom user model there directly.

Best regards,
Carsten

Mike Dewhirst

unread,
Feb 15, 2020, 5:15:49 PM2/15/20
to django...@googlegroups.com
Thank you kind sir 😀

Makes perfect sense ...

Mike
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages