diff --git a/apps/main/migrations/0050_awardtype_years.py b/apps/main/migrations/0050_awardtype_years.py new file mode 100644 index 00000000..848233aa --- /dev/null +++ b/apps/main/migrations/0050_awardtype_years.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.7 on 2020-02-04 14:06 + +import django.contrib.postgres.fields +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0049_remove_navigationbarpermission_section'), + ] + + operations = [ + migrations.AddField( + model_name='awardtype', + name='years', + field=django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1980)]), blank=True, null=True, size=None, verbose_name='years'), + ), + ] diff --git a/apps/main/migrations/0051_auto_20200204_1409.py b/apps/main/migrations/0051_auto_20200204_1409.py new file mode 100644 index 00000000..2ee8194c --- /dev/null +++ b/apps/main/migrations/0051_auto_20200204_1409.py @@ -0,0 +1,22 @@ +# Generated by Django 2.2.7 on 2020-02-04 14:09 + +import datetime + +from django.db import migrations + + +def fill_award_type_ears(apps, schemaeditor): + AwardType = apps.get_model('main', 'AwardType') + for aw in AwardType.objects.all(): + aw.years = list(range(1980, datetime.date.today().year+1)) + aw.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0050_awardtype_years'), + ] + + operations = [ + migrations.RunPython(fill_award_type_ears), + ] diff --git a/apps/main/models.py b/apps/main/models.py index 60351701..639621a3 100644 --- a/apps/main/models.py +++ b/apps/main/models.py @@ -4,8 +4,8 @@ from typing import Iterable from django.conf import settings from django.contrib.contenttypes import fields as generic from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import JSONField -from django.core.validators import EMPTY_VALUES +from django.contrib.postgres.fields import JSONField, ArrayField +from django.core.validators import EMPTY_VALUES, MinValueValidator from django.db import connections from django.db import models from django.db.models import Q @@ -230,6 +230,12 @@ class AwardType(models.Model): 'location.Country', verbose_name=_('country'), on_delete=models.CASCADE) name = models.CharField(_('name'), max_length=255) old_id = models.IntegerField(null=True, blank=True) + years = ArrayField( + models.IntegerField(validators=[MinValueValidator(1980)]), + verbose_name=_('years'), + blank=True, + null=True, + ) objects = AwardTypeQuerySet.as_manager()