mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Email is now unique
This commit is contained in:
parent
614538eefe
commit
c36d184ef9
2 changed files with 36 additions and 0 deletions
35
users/migrations/0090_auto_20200418_0206.py
Normal file
35
users/migrations/0090_auto_20200418_0206.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.28 on 2020-04-18 00:06
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db.models import Count
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0089_auto_20200418_0112'),
|
||||
]
|
||||
|
||||
|
||||
def remove_double_email_accounts(apps, schema_editor):
|
||||
db_alias = schema_editor.connection.alias
|
||||
users = apps.get_model("users", "User")
|
||||
duplicates = users.objects.using(db_alias).values('email').annotate(email_count=Count('email')).filter(email_count__gt=1)
|
||||
for email_item in duplicates:
|
||||
duplicate_users = users.objects.using(db_alias).filter(email=email_item['email']).order_by('last_login', 'registered')
|
||||
for user in duplicate_users[1:]:
|
||||
user.email=None
|
||||
user.save()
|
||||
|
||||
def revert_remove_double_email_accounts(apps, schema_editor):
|
||||
return
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remove_double_email_accounts, revert_remove_double_email_accounts),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='email',
|
||||
field=models.EmailField(blank=True, help_text='External email address allowing us to contact you.', max_length=254, null=True, unique=True),
|
||||
),
|
||||
]
|
|
@ -207,6 +207,7 @@ class User(
|
|||
email = models.EmailField(
|
||||
blank=True,
|
||||
null=True,
|
||||
unique=True,
|
||||
help_text=_("External email address allowing us to contact you."),
|
||||
)
|
||||
local_email_redirect = models.BooleanField(
|
||||
|
|
Loading…
Reference in a new issue