0026_auto_20171028_0126.py 2.78 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-10-27 23:26
from __future__ import unicode_literals

from django.db import migrations, models


def create_type(apps, schema_editor):
    Cotisation = apps.get_model('cotisations', 'Cotisation')
    Vente = apps.get_model('cotisations', 'Vente')
    Article = apps.get_model('cotisations', 'Article')
    db_alias = schema_editor.connection.alias
Gabriel Detraz's avatar
Gabriel Detraz committed
13
    articles = Article.objects.using(db_alias).all()
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    ventes = Vente.objects.using(db_alias).all()
    cotisations = Cotisation.objects.using(db_alias).all()
    for article in articles:
        if article.iscotisation:
            article.type_cotisation='All'
            article.save(using=db_alias)
    for vente in ventes:
        if vente.iscotisation:
            vente.type_cotisation='All'
            vente.save(using=db_alias)
    for cotisation in cotisations:
        cotisation.type_cotisation='All'
        cotisation.save(using=db_alias)

def delete_type(apps, schema_editor):
    Vente = apps.get_model('cotisations', 'Vente')
    Article = apps.get_model('cotisations', 'Article')
    db_alias = schema_editor.connection.alias
    articles = Articles.objects.using(db_alias).all()
    ventes = Vente.objects.using(db_alias).all()
    for article in articles:
        if article.type_cotisation:
            article.iscotisation=True
        else:
            article.iscotisation=False
        article.save(using=db_alias)
    for vente in ventes:
        if vente.iscotisation:
            vente.iscotisation=True
        else:
            vente.iscotisation=False
        vente.save(using=db_alias)

class Migration(migrations.Migration):

    dependencies = [
        ('cotisations', '0025_article_type_user'),
    ]

    operations = [
        migrations.AddField(
            model_name='article',
            name='type_cotisation',
Gabriel Detraz's avatar
Gabriel Detraz committed
57
            field=models.CharField(blank=True, choices=[('Connexion', 'Connexion'), ('Adhesion', 'Adhesion'), ('All', 'All')], default=None, max_length=255, null=True),
58 59 60 61
        ),
        migrations.AddField(
            model_name='cotisation',
            name='type_cotisation',
62
            field=models.CharField(choices=[('Connexion', 'Connexion'), ('Adhesion', 'Adhesion'), ('All', 'All')], max_length=255, default='All'),
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
        ),
        migrations.AddField(
            model_name='vente',
            name='type_cotisation',
            field=models.CharField(blank=True, choices=[('Connexion', 'Connexion'), ('Adhesion', 'Adhesion'), ('All', 'All')], max_length=255, null=True),
        ),
        migrations.RunPython(create_type, delete_type),
        migrations.RemoveField(
            model_name='article',
            name='iscotisation',
        ),
        migrations.RemoveField(
            model_name='vente',
            name='iscotisation',
        ),
    ]