reusable App XOR custom user model?

26 views
Skip to first unread message

guettli

unread,
Nov 3, 2020, 1:59:37 PM11/3/20
to Django users
Quoting the Docs:

> If you’re starting a new project, it’s highly recommended to set up a custom user model, even if the default User model is sufficient for you. This model behaves identically to the default user model, but you’ll be able to customize it in the future if the need arises:

But this means: My code won't be reusable.

Some lines below:

> Reusable apps shouldn’t implement a custom user model. A project may use many apps, and two reusable apps that implemented a custom user model couldn’t be used together. If you need to store per user information in your app, use a ForeignKey or OneToOneField to settings.AUTH_USER_MODEL as described below.

I think both sentences somehow contradict, since AFAIK it is highly recommended to
write reusable apps.

What do you recommend

reusable App   XOR    custom user model?

Regards,
  Thomas

ANi

unread,
Nov 5, 2020, 1:05:49 AM11/5/20
to Django users
Hi Thomas, 

The first one focuses on "project" and the second one focuses on "apps".
They don't contradict with each,  a project may use many apps, they are different.
If you want a reusable app then don't include a custom user model in it.

Ani.
guettli 在 2020年11月4日 星期三上午2:59:37 [UTC+8] 的信中寫道:

Andréas Kühne

unread,
Nov 5, 2020, 4:35:33 AM11/5/20
to django...@googlegroups.com
Like Ani said, 

There are different use cases. If you want to make a reusable app - that can be put up on pypi for example - then you shouldn't add a custom user model, but you can connect to the user model instead (this was previously recommended in django with the "UserProfile" solution).

However - if you are writing your own project - that you will be building on in the future, then the first thing I do is always to create a new user model. The reason for this is that it's hard to change that if you already have started writing your project and have a database in place and so on.

Regards,

Andréas


--
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/93d808ff-00ac-46cc-8c4b-eb05002aec91n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages