Initial projects
This commit is contained in:
parent
95cc7235b0
commit
8552e5f12c
9 changed files with 112 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
||||||
venv
|
venv
|
||||||
staticfiles
|
staticfiles
|
||||||
|
data
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*.pyc
|
*.pyc
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|
0
ccdb/projects/__init__.py
Normal file
0
ccdb/projects/__init__.py
Normal file
6
ccdb/projects/admin.py
Normal file
6
ccdb/projects/admin.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from .models import Project
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Project)
|
33
ccdb/projects/migrations/0001_initial_project.py
Normal file
33
ccdb/projects/migrations/0001_initial_project.py
Normal 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')]),
|
||||||
|
),
|
||||||
|
]
|
38
ccdb/projects/migrations/0002_project_data.py
Normal file
38
ccdb/projects/migrations/0002_project_data.py
Normal 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),
|
||||||
|
]
|
0
ccdb/projects/migrations/__init__.py
Normal file
0
ccdb/projects/migrations/__init__.py
Normal file
21
ccdb/projects/models.py
Normal file
21
ccdb/projects/models.py
Normal 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']
|
|
@ -38,6 +38,7 @@ THIRD_PARTY_APPS = (
|
||||||
# Apps specific for this project go here.
|
# Apps specific for this project go here.
|
||||||
LOCAL_APPS = (
|
LOCAL_APPS = (
|
||||||
'ccdb.users', # custom users app
|
'ccdb.users', # custom users app
|
||||||
|
'ccdb.projects',
|
||||||
)
|
)
|
||||||
|
|
||||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||||
|
|
|
@ -536,18 +536,18 @@ class TblLuProcessTypes(models.Model):
|
||||||
unique_together = (('Process_Type', 'Process_Type_Code'),)
|
unique_together = (('Process_Type', 'Process_Type_Code'),)
|
||||||
|
|
||||||
|
|
||||||
class TblLuProjects(models.Model):
|
# class TblLuProjects(models.Model):
|
||||||
projectid = models.AutoField(db_column='ProjectID', primary_key=True) # Field name made lowercase.
|
# 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 = 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.
|
# 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.
|
# 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.
|
# 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.
|
# sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase.
|
||||||
|
#
|
||||||
class Meta:
|
# class Meta:
|
||||||
managed = False
|
# managed = False
|
||||||
db_table = 'tbl_LU_Projects'
|
# db_table = 'tbl_LU_Projects'
|
||||||
unique_together = (('Project', 'Project_Code'),)
|
# unique_together = (('Project', 'Project_Code'),)
|
||||||
|
|
||||||
|
|
||||||
class TblLuReagents(models.Model):
|
class TblLuReagents(models.Model):
|
||||||
|
|
Loading…
Add table
Reference in a new issue