Initial grants
This commit is contained in:
parent
8552e5f12c
commit
3572c75eff
5 changed files with 94 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Project
|
||||
from .models import Project, Grant
|
||||
|
||||
|
||||
admin.site.register(Project)
|
||||
admin.site.register(Grant)
|
||||
|
|
31
ccdb/projects/migrations/0003_initial_grant.py
Normal file
31
ccdb/projects/migrations/0003_initial_grant.py
Normal 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')]),
|
||||
),
|
||||
]
|
36
ccdb/projects/migrations/0004_grant_data.py
Normal file
36
ccdb/projects/migrations/0004_grant_data.py
Normal 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),
|
||||
]
|
|
@ -19,3 +19,17 @@ class Project(models.Model):
|
|||
class Meta:
|
||||
unique_together = ('name', 'code')
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
class Grant(models.Model):
|
||||
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(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
unique_together = ('title', 'code',)
|
||||
ordering = ['sort_order']
|
||||
|
|
|
@ -425,17 +425,17 @@ class TblLuGrantReports(models.Model):
|
|||
db_table = 'tbl_LU_Grant_Reports'
|
||||
|
||||
|
||||
class TblLuGrants(models.Model):
|
||||
grantid = models.AutoField(db_column='GrantID', primary_key=True) # Field name made lowercase.
|
||||
grant_title = models.CharField(db_column='Grant_Title', max_length=200) # Field name made lowercase.
|
||||
grant_code = models.CharField(db_column='Grant_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
|
||||
grant_short_description = models.CharField(db_column='Grant_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase.
|
||||
sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase.
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'tbl_LU_Grants'
|
||||
unique_together = (('Grant_Title', 'Grant_Code'),)
|
||||
# class TblLuGrants(models.Model):
|
||||
# grantid = models.AutoField(db_column='GrantID', primary_key=True) # Field name made lowercase.
|
||||
# grant_title = models.CharField(db_column='Grant_Title', max_length=200) # Field name made lowercase.
|
||||
# grant_code = models.CharField(db_column='Grant_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
|
||||
# grant_short_description = models.CharField(db_column='Grant_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase.
|
||||
# sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase.
|
||||
#
|
||||
# class Meta:
|
||||
# managed = False
|
||||
# db_table = 'tbl_LU_Grants'
|
||||
# unique_together = (('Grant_Title', 'Grant_Code'),)
|
||||
|
||||
|
||||
class TblLuMaterials(models.Model):
|
||||
|
|
Loading…
Add table
Reference in a new issue