Initial grants

This commit is contained in:
Matthew Dillon 2016-01-20 11:51:43 -07:00
parent 8552e5f12c
commit 3572c75eff
5 changed files with 94 additions and 12 deletions

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0002_project_data'),
]
operations = [
migrations.CreateModel(
name='Grant',
fields=[
('id', models.AutoField(serialize=False, verbose_name='ID', auto_created=True, primary_key=True)),
('title', models.CharField(max_length=200)),
('code', models.CharField(max_length=10, blank=True)),
('description', models.CharField(max_length=255, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
],
options={
'ordering': ['sort_order'],
},
),
migrations.AlterUniqueTogether(
name='grant',
unique_together=set([('title', 'code')]),
),
]

View file

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import csv
import os
from django.db import migrations, models
def import_grants(apps, schema_editor):
Grant = apps.get_model('projects', 'Grant')
filename = 'data/tbl_LU_Grants.csv'
if os.path.exists(filename):
with open(filename) as f:
fieldnames = ['id', 'title', 'code', 'description', 'sort_order']
reader = csv.DictReader(f, fieldnames=fieldnames)
for r in reader:
r['sort_order'] = None
p = Grant(**r)
p.save()
def remove_grants(apps, schema_editor):
Grant = apps.get_model('projects', 'Grant')
Grant.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('projects', '0003_initial_grant'),
]
operations = [
migrations.RunPython(import_grants, remove_grants),
]