years for award types
This commit is contained in:
parent
1c6ec90fbf
commit
8f899905ec
20
apps/main/migrations/0050_awardtype_years.py
Normal file
20
apps/main/migrations/0050_awardtype_years.py
Normal 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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
22
apps/main/migrations/0051_auto_20200204_1409.py
Normal file
22
apps/main/migrations/0051_auto_20200204_1409.py
Normal 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),
|
||||||
|
]
|
||||||
|
|
@ -4,8 +4,8 @@ from typing import Iterable
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes import fields as generic
|
from django.contrib.contenttypes import fields as generic
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField, ArrayField
|
||||||
from django.core.validators import EMPTY_VALUES
|
from django.core.validators import EMPTY_VALUES, MinValueValidator
|
||||||
from django.db import connections
|
from django.db import connections
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
@ -230,6 +230,12 @@ class AwardType(models.Model):
|
||||||
'location.Country', verbose_name=_('country'), on_delete=models.CASCADE)
|
'location.Country', verbose_name=_('country'), on_delete=models.CASCADE)
|
||||||
name = models.CharField(_('name'), max_length=255)
|
name = models.CharField(_('name'), max_length=255)
|
||||||
old_id = models.IntegerField(null=True, blank=True)
|
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()
|
objects = AwardTypeQuerySet.as_manager()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user