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

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
venv
staticfiles
data
*.py[cod]
*.pyc
__pycache__

View file

6
ccdb/projects/admin.py Normal file
View file

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Project
admin.site.register(Project)

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

21
ccdb/projects/models.py Normal file
View file

@ -0,0 +1,21 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from autoslug import AutoSlugField
class Project(models.Model):
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(blank=True, null=True)
slug = AutoSlugField(populate_from='name')
def __str__(self):
return self.name
class Meta:
unique_together = ('name', 'code')
ordering = ['sort_order']

View file

@ -38,6 +38,7 @@ THIRD_PARTY_APPS = (
# Apps specific for this project go here.
LOCAL_APPS = (
'ccdb.users', # custom users app
'ccdb.projects',
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps

View file

@ -536,18 +536,18 @@ class TblLuProcessTypes(models.Model):
unique_together = (('Process_Type', 'Process_Type_Code'),)
class TblLuProjects(models.Model):
projectid = models.AutoField(db_column='ProjectID', primary_key=True) # Field name made lowercase.
project = models.CharField(db_column='Project', max_length=100) # Field name made lowercase.
project_code = models.CharField(db_column='Project_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
iacuc_number = models.CharField(db_column='IACUC_Number', max_length=25, blank=True, null=True) # Field name made lowercase.
project_short_description = models.CharField(db_column='Project_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_Projects'
unique_together = (('Project', 'Project_Code'),)
# class TblLuProjects(models.Model):
# projectid = models.AutoField(db_column='ProjectID', primary_key=True) # Field name made lowercase.
# project = models.CharField(db_column='Project', max_length=100) # Field name made lowercase.
# project_code = models.CharField(db_column='Project_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
# iacuc_number = models.CharField(db_column='IACUC_Number', max_length=25, blank=True, null=True) # Field name made lowercase.
# project_short_description = models.CharField(db_column='Project_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_Projects'
# unique_together = (('Project', 'Project_Code'),)
class TblLuReagents(models.Model):