Treatment

This commit is contained in:
Matthew Ryan Dillon 2016-02-01 14:39:59 -07:00
parent ab1d605c95
commit a8a87f7ddb
5 changed files with 65 additions and 17 deletions

View file

@ -1,6 +1,7 @@
from django.contrib import admin
from .models import Flaw, Experiment, ProtocolAttachment, TreatmentType
from .models import Flaw, Experiment, ProtocolAttachment, TreatmentType, \
Treatment
class FlawAdmin(admin.ModelAdmin):
@ -38,7 +39,19 @@ class TreatmentTypeAdmin(admin.ModelAdmin):
'description', 'sort_order')
class TreatmentAdmin(admin.ModelAdmin):
list_display = ('treatment_type', 'container', 'study_location', 'species',
'sex', 'flaw')
list_display_links = ('treatment_type',)
search_fields = ('treatment_type', 'container', 'study_location', 'species',
'sex', 'flaw')
list_per_page = 25
fields = ('treatment_type', 'container', 'study_location', 'species',
'sex', 'flaw')
admin.site.register(Flaw, FlawAdmin)
admin.site.register(Experiment, ExperimentAdmin)
admin.site.register(ProtocolAttachment, ProtocolAttachmentAdmin)
admin.site.register(TreatmentType, TreatmentTypeAdmin)
admin.site.register(Treatment, TreatmentAdmin)

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('misc', '0001_initial'),
('species', '0003_collectionspecies'),
('locations', '0002_remove_site_fk_dupes'),
('experiments', '0002_treatment_type'),
]
operations = [
migrations.CreateModel(
name='Treatment',
fields=[
('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)),
('sex', models.CharField(max_length=25)),
('container', models.ForeignKey(blank=True, null=True, to='misc.Container')),
('flaw', models.ForeignKey(blank=True, null=True, to='experiments.Flaw')),
('species', models.ForeignKey(to='species.Species')),
('study_location', models.ForeignKey(to='locations.StudyLocation')),
('treatment_type', models.ForeignKey(to='experiments.TreatmentType')),
],
),
]

View file

@ -51,8 +51,22 @@ class TreatmentType(models.Model):
slug = AutoSlugField(populate_from='name')
def __str__(self):
return self.name
return "{} {} {} {}".format(self.experiment, self.name,
self.treatment_type, self.placement)
class Meta:
unique_together = ('experiment', 'name')
ordering = ['sort_order']
class Treatment(models.Model):
treatment_type = models.ForeignKey(TreatmentType)
container = models.ForeignKey('misc.Container', blank=True, null=True)
study_location = models.ForeignKey('locations.StudyLocation')
species = models.ForeignKey('species.Species')
sex = models.CharField(max_length=25)
flaw = models.ForeignKey(Flaw, blank=True, null=True)
def __str__(self):
return "{} {} {} {}".format(self.treatment_type, self.study_location,
self.species, self.sex)