1

I have a quick question,

In the admin panel, you can set the user's email as unique via:

User._meta.get_field('email')._unique = True

And I was wondering if you could also make it required like the above snippet, enforcing it through the database if so, how do I do that?

Juan Carlos Asuncion
  • 927
  • 2
  • 10
  • 26

1 Answers1

0

I am not sure if you are asking specifically for the admin login, but assuming you are ok logging in with the regular django-allauth flow, all you need to do is add the following settings (settings.py):

ACCOUNT_USER_MODEL_EMAIL_FIELD= 'email'
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = True   
ACCOUNT_EMAIL_REQUIRED = True

If you want to switch to using the email itself for logging in (in which case, this will also make it required, and work on the admin login as well, add also

ACCOUNT_AUTHENTICATION_METHOD = 'email'

Hope this helps

dkarchmer
  • 5,434
  • 4
  • 24
  • 37
  • Your app's `settings.py` – Alex Panov Mar 14 '16 at 21:21
  • Clarify answer that this is on the settings.py as Alex said – dkarchmer Mar 14 '16 at 21:23
  • If what I understood is correct, I'll place this anywhere in my `settings.py` file. if that's the case then nothing happened, I can still leave the email blank – Juan Carlos Asuncion Mar 14 '16 at 22:01
  • What was not clear from your question (and a disclaimer in my answer) is if you are using the django-allauth, or the django admin login. Can you clarify that? Are you logging in using /admin/login? or something like /account/login? One is managed by django, and one by allauth. – dkarchmer Mar 14 '16 at 22:04