Should a custom user have meta.swappable

158 views
Skip to first unread message

Mike Dewhirst

unread,
Dec 18, 2019, 1:48:33 AM12/18/19
to Django users
Looking at django.contrib.auth.models I see ...

class User(AbstractUser):

    """

    Users within the Django authentication system are represented by this

    model.

    Username and password are required. Other fields are optional.

    """

    class Meta(AbstractUser.Meta):

        swappable = 'AUTH_USER_MODEL'


... and I wonder if my custom user model should have an identical Meta
attibute?

Thanks

Mike

James Bennett

unread,
Dec 18, 2019, 1:58:01 AM12/18/19
to django...@googlegroups.com
On Tue, Dec 17, 2019 at 10:47 PM Mike Dewhirst <mi...@dewhirst.com.au> wrote:
... and I wonder if my custom user model should have an identical Meta
attibute?

No, The 'swappable' Meta attribute is private/undocumented API; if it were meant to be a thing you needed to set, the documentation would tell you to set it, rather than it being hidden away in the source code.

It exists to support Django's ability to replace the default User model with a custom-defined model class; only the model class that is meant to be replaceable declares the 'swappable' attribute.

Mike Dewhirst

unread,
Dec 18, 2019, 2:07:40 AM12/18/19
to django...@googlegroups.com
Thank you James

M
> --
> 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/CAL13Cg-G7zqWABf_VyZeUO9PtY67d5S-S7gpGdQwQXwR27mSbA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAL13Cg-G7zqWABf_VyZeUO9PtY67d5S-S7gpGdQwQXwR27mSbA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Reply all
Reply to author
Forward
0 new messages