使用Django User admin使电子邮件字段唯一 [英] Making email field unique with Django User admin

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

问题描述

有一个几乎类似的问题:如何通过Django中的contrib.auth使模型用户中的电子邮件字段唯一

There was a nearly similar question: How to make email field unique in model User from contrib.auth in Django

解决方案并不完美:验证电子邮件的唯一性。提供的解决方案很有趣。它不允许修改使用户保持原封不动的用户。如何解决?

The solution was not perfect: Validating email for uniqueness. The solution provided is rather funny. It disallows modifications to User that leave email intact. How to fix it? Thanks in advance!

推荐答案

感谢Ofri Raviv,但我所看到的并不是我所需要的。因此,我解决了自己的问题,现在我想分享一下提示:

Thanks to Ofri Raviv but what I've seen is not what I needed. So I resolved my own issue and now I'd like to share the tips:


  1. 使用用户名代替电子邮件,排除电子邮件从表格。

  1. Use username instead of email, exclude email from the form. Mask its label as email.

子类用户,并创建一个UNIQUE字段来接收电子邮件地址,将其掩码为电子邮件,从表单中排除原始电子邮件字段。 / p>

Subclass User and create a UNIQUE field which receives email addresses, mask it as email, exclude original email field from the form.

就这么简单,但花了我一些时间。希望它能帮助有同样需求的其他人。

It's that simple but took me some time. Hope it help others with the same need.

这篇关于使用Django User admin使电子邮件字段唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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