Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Belgian Biodiversity Platform
astapor
Commits
81e0a0d0
Commit
81e0a0d0
authored
Jun 20, 2017
by
Nicolas Noé
Browse files
Improved station management.
parent
0742ddb5
Changes
3
Hide whitespace changes
Inline
Side-by-side
website/specimens/admin.py
View file @
81e0a0d0
...
...
@@ -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
):
...
...
website/specimens/management/commands/csv_import.py
View file @
81e0a0d0
...
...
@@ -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
)
...
...
website/specimens/models.py
View file @
81e0a0d0
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment