years for award types

This commit is contained in:
alex 2020-02-04 17:19:09 +03:00
parent 1c6ec90fbf
commit 8f899905ec
3 changed files with 50 additions and 2 deletions

View File

@ -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'),
),
]

View File

@ -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),
]

View File

@ -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()