Initial projects
This commit is contained in:
		
							parent
							
								
									95cc7235b0
								
							
						
					
					
						commit
						8552e5f12c
					
				
					 9 changed files with 112 additions and 12 deletions
				
			
		
							
								
								
									
										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']
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue