如何从 Django 中的 contrib.auth 使模型用户中的电子邮件字段唯一 [英] How to make email field unique in model User from contrib.auth in Django

查看:26
本文介绍了如何从 Django 中的 contrib.auth 使模型用户中的电子邮件字段唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过确保电子邮件字段条目的唯一性来修补 contrib.auth 的标准用户模型:

I need to patch the standard User model of contrib.auth by ensuring the email field entry is unique:

User._meta.fields[4].unique = True

代码中最好的地方是什么?

Where is best place in code to do that?

我想避免使用数字fields[4].最好使用 fields['email'],但 fields 不是字典,只是列表.

I want to avoid using the number fields[4]. It's better to user fields['email'], but fields is not dictionary, only list.

另一个想法可能是打开一张新票并在settings.py中上传一个带有新参数的补丁:

Another idea may be to open a new ticket and upload a patch with new parameter inside settings.py:

AUTH_USER_EMAIL_UNIQUE = True

关于在 Django 用户模型中实现电子邮件地址唯一性的最正确方法有什么建议吗?

Any suggestions on the most correct way to achieve email address uniqueness in the Django User model?

推荐答案

太棒了,但我找到了最适合我的解决方案!

It's amazing, but I found a best solution for me!

django-registration 具有检查电子邮件字段唯一性的表单:RegistrationFormUniqueEmail

django-registration have form with checking uniqueness of email field: RegistrationFormUniqueEmail

用法示例这里

这篇关于如何从 Django 中的 contrib.auth 使模型用户中的电子邮件字段唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆