kpsul/gestioncof/migrations/0016_unique_clippers.py

45 lines
1.4 KiB
Python
Raw Normal View History

2019-01-14 22:46:16 +01:00
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-01-14 21:36
from __future__ import unicode_literals
from django.db import migrations, models
def empty_clippers_to_null(apps, schema_editor):
CofProfile = apps.get_model("gestioncof", "CofProfile")
CofProfile.objects.filter(login_clipper="").update(login_clipper=None)
def null_clippers_to_empty(apps, schema_editor):
CofProfile = apps.get_model("gestioncof", "CofProfile")
CofProfile.objects.filter(login_clipper__isnull=True).update(login_clipper="")
class Migration(migrations.Migration):
dependencies = [("gestioncof", "0015_psql_choices_niveaux")]
operations = [
# First, only set null to True (unique is still False)
migrations.AlterField(
model_name="cofprofile",
name="login_clipper",
field=models.CharField(
blank=True, max_length=32, null=True, verbose_name="Login clipper"
),
),
# Then, set all empty login_clippers to null
migrations.RunPython(empty_clippers_to_null),
# Finally set unique to True
migrations.AlterField(
model_name="cofprofile",
name="login_clipper",
field=models.CharField(
blank=True,
max_length=32,
null=True,
unique=True,
verbose_name="Login clipper",
),
),
]