8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 23:22:25 +00:00

Email is now unique

This commit is contained in:
Gabriel Detraz 2020-04-18 04:11:12 +02:00
parent 614538eefe
commit c36d184ef9
2 changed files with 36 additions and 0 deletions

View 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),
),
]

View file

@ -207,6 +207,7 @@ class User(
email = models.EmailField( email = models.EmailField(
blank=True, blank=True,
null=True, null=True,
unique=True,
help_text=_("External email address allowing us to contact you."), help_text=_("External email address allowing us to contact you."),
) )
local_email_redirect = models.BooleanField( local_email_redirect = models.BooleanField(