ccdb-api/ccdb/experiments/models.py
2016-02-01 14:39:59 -07:00

72 lines
2.3 KiB
Python

from django.db import models
from autoslug import AutoSlugField
class Flaw(models.Model):
name = models.CharField(max_length=200)
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:
ordering = ['sort_order']
class Experiment(models.Model):
name = models.CharField(max_length=150)
code = models.CharField(max_length=10, blank=True)
description = models.CharField(max_length=255, blank=True)
flaw = models.ForeignKey(Flaw, blank=True, null=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']
class ProtocolAttachment(models.Model):
experiment = models.ForeignKey(Experiment)
protocol = models.FileField(upload_to='experiments/protocols/%Y/%m/%d')
def __str__(self):
return self.protocol
class TreatmentType(models.Model):
experiment = models.ForeignKey(Experiment, blank=True, null=True)
name = models.CharField(max_length=200)
code = models.CharField(max_length=25, blank=True)
treatment_type = models.CharField(max_length=50, blank=True)
placement = 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 "{} {} {} {}".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)