mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 04:13:12 +00:00
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
# -*- 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),
|
|
),
|
|
]
|