Commit 81e0a0d0 authored by Nicolas Noé's avatar Nicolas Noé
Browse files

Improved station management.

parent 0742ddb5
......@@ -41,7 +41,8 @@ class FixationAdmin(admin.ModelAdmin):
@admin.register(Station)
class StationAdmin(admin.ModelAdmin):
pass
list_display = ('name', 'expedition')
list_filter = ('expedition', )
@admin.register(Expedition)
class ExpeditionAdmin(admin.ModelAdmin):
......
......@@ -6,7 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.core.management.base import BaseCommand, CommandError
from django.contrib.gis.geos import Point
from specimens.models import Person, SpecimenLocation, Specimen, Fixation, Expedition, Station
from specimens.models import Person, SpecimenLocation, Specimen, Fixation, Expedition, Station, UNKNOWN_STATION_NAME
MODELS_TO_TRUNCATE = [Station, Expedition, Fixation, Person, SpecimenLocation, Specimen]
......@@ -22,6 +22,9 @@ def get_or_create_station_and_expedition(station_name, expedition_name):
:rtype: Station
"""
if station_name == '':
station_name = UNKNOWN_STATION_NAME
try: # A station already exists for the correct expedition?
return Station.objects.get(name=station_name, expedition__name=expedition_name)
......
from django.contrib.gis.db import models
from django.contrib.postgres.fields import FloatRangeField
UNKNOWN_STATION_NAME = '<Unknown>' # Sometimes we need a "fake" station to link Specimen to Expedition
class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
......@@ -12,24 +14,28 @@ class Person(models.Model):
def __str__(self):
return self.first_name + ' ' + self.last_name
class SpecimenLocation(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Fixation(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Expedition(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Station(models.Model):
name = models.CharField(max_length=100)
expedition = models.ForeignKey(Expedition)
......@@ -39,6 +45,7 @@ class Station(models.Model):
def __str__(self):
return "{name} (from exp. {exp_name})".format(name=self.name, exp_name=self.expedition)
class Specimen(models.Model):
specimen_id = models.IntegerField(unique=True) # ID from the lab, not Django's PK
scientific_name = models.CharField(max_length=100)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment