Admin Section API (#11)

Models for managing admin pages
This commit is contained in:
Matthew Ryan Dillon 2016-09-05 17:03:01 -07:00 committed by GitHub
parent 8e08cab3c4
commit 910d3b4beb
15 changed files with 310 additions and 36 deletions

View file

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-29 04:00
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='AdminEntry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('package', models.CharField(max_length=255)),
('model', models.CharField(max_length=255)),
('sort', models.IntegerField()),
],
),
migrations.CreateModel(
name='AdminSection',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('sort', models.IntegerField()),
],
),
migrations.AddField(
model_name='adminentry',
name='section',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='utils.AdminSection'),
),
]

View file

@ -0,0 +1,72 @@
from collections import namedtuple
from django.db import migrations
Section = namedtuple('Section', ['name', 'package', 'entries'])
class Migration(migrations.Migration):
def migrate(apps, schema_editor):
AdminSection = apps.get_model('utils', 'AdminSection')
AdminEntry = apps.get_model('utils', 'AdminEntry')
# Clean up any old stuff
for model in [AdminEntry, AdminSection]:
model.objects.all().delete()
data = [
Section('Collections', 'collections_ccdb', [
'collectiontype', 'collectionmethod', 'flaw', 'adfgpermit',
'datasheetattachment', 'collectiontrap', 'collection'
]),
Section('Experiments', 'experiments', [
'flaw', 'experiment', 'protocolattachment', 'treatmenttype',
'treatment', 'treatmentreplicate', 'alivedeadcount'
]),
Section('Locations', 'locations', [
'region', 'site', 'municipallocation', 'studylocation',
'storagelocation'
]),
Section('Misc.', 'misc', [
'measurementunit', 'measurementtype', 'container', 'material',
'color'
]),
Section('Processing', 'processing', [
'processtype', 'reagent', 'flaw'
]),
Section('Projects', 'projects', [
'project', 'grant', 'grantreport'
]),
Section('Species', 'species', [
'species', 'trapspecies', 'collectionspecies'
]),
Section('Users', 'users', [
'user'
]),
Section('Utils', 'utils', [
'adminsection', 'adminentry'
]),
]
for i, adminsection in enumerate(data):
section = AdminSection.objects.create(name=adminsection.name,
sort=i)
for j, entry in enumerate(adminsection.entries):
AdminEntry.objects.create(package=adminsection.package,
model=entry, section=section, sort=j)
def rollback(apps, schema_editor):
AdminSection = apps.get_model('utils', 'AdminSection')
AdminEntry = apps.get_model('utils', 'AdminEntry')
for model in [AdminEntry, AdminSection]:
model.objects.all().delete()
dependencies = [
('utils', '0001_initial'),
]
operations = [
migrations.RunPython(migrate, rollback),
]