Monday, January 26, 2015

Re: Django default auth user but unique email

If you want any sort of enforcement of a unique email address at the database level, you'll need a custom user model. If you don't care about that, all you'd need to do is override the user forms and create a custom clean_email function that checks for duplicates before saving the form data. Not 100% guaranteed on a high traffic site unless you wrap it in a transaction, and will become expensive to check as you gather more users in the database, especially since the email field won't be indexed using the standard user model, and would result in a slower string-matching query against the entire table rather than an index-based comparison.

If you have any special requirements for the user in your application, I highly recommend you bite the bullet and create a custom user model. It's not terribly difficult, and will better posture you down the road in the event that your requirements change, not to mention you can enforce uniqueness at the database level. 

-James

On Jan 26, 2015 7:01 PM, "Bruce Li" <bruce.li@gmail.com> wrote:
To be more specific, I want the username and email in default user model both to be unique and not blank.

On Tuesday, January 27, 2015 at 10:56:14 AM UTC+8, Bruce Li wrote:
Hi,

I want to build my user management based on default django users. But I want emails to be unique as well. Is it possible to do that without the need to create a custom user model and user managment?


Thanks,
- Bruce

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e415b13a-2b38-4f1b-80e6-4ba808a09175%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW9OvqKg9PCVB3K_hRTk0NQcR6DJNOt%2BdDmkWzzkMVe5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment