Initial projects

This commit is contained in:
Matthew Dillon 2016-01-20 11:35:48 -07:00
parent 95cc7235b0
commit 8552e5f12c
9 changed files with 112 additions and 12 deletions

View file

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import autoslug.fields
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='Project',
fields=[
('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('code', models.CharField(max_length=10, blank=True)),
('iacuc_number', models.CharField(max_length=25, blank=True)),
('description', models.CharField(max_length=255, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)),
],
options={
'ordering': ['sort_order'],
},
),
migrations.AlterUniqueTogether(
name='project',
unique_together=set([('name', 'code')]),
),
]

View file

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import csv
import os
from django.db import migrations, models
def import_projects(apps, schema_editor):
Project = apps.get_model('projects', 'Project')
filename = 'data/tbl_LU_Projects.csv'
if os.path.exists(filename):
with open(filename) as f:
fieldnames = ['id', 'name', 'code', 'iacuc_number',
'description', 'sort_order']
reader = csv.DictReader(f, fieldnames=fieldnames)
for r in reader:
r['sort_order'] = int(float(r['sort_order']))
p = Project(**r)
p.save()
def remove_projects(apps, schema_editor):
print("removing projects...")
Project = apps.get_model("projects", "Project")
Project.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('projects', '0001_initial_project'),
]
operations = [
migrations.RunPython(import_projects, remove_projects),
]

View file