How to make email field unique in model User from contrib.auth in Django

后端 未结 19 2058
夕颜
夕颜 2020-11-27 11:47

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
<         


        
19条回答
  •  爱一瞬间的悲伤
    2020-11-27 12:02

    One possible way to do this is to have a pre-save hook on the User object and reject the save of the email already exists in the table.

提交回复
热议问题