8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-20 10:23:12 +00:00
re2o/cotisations/migrations/0047_article_need_membership_init.py
histausse a01c9e2303 Add the need_membership field to article
This field is a boolean indicating if the article can be purshased by
nonmembers.
2020-10-08 22:23:34 +02:00

28 lines
919 B
Python

# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-09-25 16:45
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cotisations', '0046_article_need_membership'),
]
def init_need_membership(apps, schema_editor):
db_alias = schema_editor.connection.alias
article = apps.get_model("cotisations", "Article")
articles = article.objects.using(db_alias).all()
for art in articles:
v = False
v = v or bool(art.duration_membership)
v = v or bool(art.duration_days_membership)
v = v or not (bool(art.duration_connection) or bool(art.duration_days_connection))
art.need_membership = v
art.save()
operations = [
migrations.RunPython(init_need_membership, lambda *args, **kargs: None),
]