> Note that EmailUser *doesn't* have a Meta: swappable definition. There is
nothing on this model that says "I am swappable", or "I am an appropriate
substitute for User".
Ah, this is were the misunderstanding was. authtools does actually set
swappable on its replacement user, too[1]. The two definitions look like
this:
class User(Model):
username = models.CharField()
USERNAME_FIELD = 'username'
class Meta:
swappable = 'AUTH_USER_MODEL'
class EmailUser(Model):
email = models.CharField()
USERNAME_FIELD = 'email'
class Meta:
swappable = 'AUTH_USER_MODEL'
> How does Django identify that EmailUser *shouldn't* be synchronised to
the database?
The existing swappable mechanism takes care of it. Only the model
referenced by settings.AUTH_USER_MODEL will be installed, not both.
> we still have a problem -- We can't just say
"contrib.auth.forms.AuthenticationForm", because this form needs to change
depending on the model that is in use. We have similar problems with admin,
and potentially with views and URLs.
It's straightforward to make the forms, views, and URLs work without
checking what user model is installed, and this is the approach authtools
takes. We can agree that code like `if settings.AUTH_USER_MODEL ==
auth.EmailUser"` is absolutely awful, so it's nice that it's not required
to implement forms that work with custom user models. The forms from
authtools will work with any user model, not just authtools.User and
auth.User. It doesn't use any ugly switches on the type of the installed
user model to do it either. (Note: the views and URLs don't actually have
to change to accommodate EmailUser. authtools ships with the CBV auth views
simply because #17209[2] has stalled.)
[1]:
https://github.com/fusionbox/django-authtools/blob/master/authtools/models.py#L86
[2]: https://code.djangoproject.com/ticket/17209
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.