admin.py 1.94 KB
Newer Older
1
from django.contrib import admin
2
3

from django import forms
4
from .models import Specimen, SpecimenLocation, Person, Fixation, Station, Expedition, SpecimenPicture
5
6
7
8
9
10
11
12
13
14
from .widgets import LatLongWidget


# Custom form to provide lat/lon widget instead of OL map.
class MyAdminForm(forms.ModelForm):

    class Meta:
        model = Specimen
        fields = "__all__"
        widgets = {
15
            'coords': LatLongWidget
16
17
        }

18

19
20
21
class SpecimenPictureInline(admin.TabularInline):
    model = SpecimenPicture

22
@admin.register(Specimen)
23
class SpecimenAdmin(admin.ModelAdmin):
24
    form = MyAdminForm
25

26
    list_display = ('specimen_id', 'station', 'scientific_name', 'identified_by', 'specimen_location', 'depth_str', 'fixation')
Nicolas Noé's avatar
Nicolas Noé committed
27
    list_filter = ('identified_by', 'specimen_location', 'fixation', 'station__expedition')
28
29
    search_fields = ['scientific_name', 'specimen_id']
    # TODO: document searchable fields in template? (https://stackoverflow.com/questions/11411622/add-help-text-for-search-field-in-admin-py)
30

31
32
33
    inlines = [
        SpecimenPictureInline,
    ]
34

35
36
37
38
39
40
41
42
    class Media:
        css = {
             "all": ("https://cdnjs.cloudflare.com/ajax/libs/ol3/3.15.1/ol.css",)
        }

        js = ("https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js",
              "https://cdnjs.cloudflare.com/ajax/libs/ol3/3.15.1/ol.js")

43
@admin.register(SpecimenLocation)
44
45
46
class SpecimenLocationAdmin(admin.ModelAdmin):
    pass

47
48

@admin.register(Person)
49
50
51
class PersonAdmin(admin.ModelAdmin):
    pass

52
@admin.register(Fixation)
53
54
55
class FixationAdmin(admin.ModelAdmin):
    pass

56
57
@admin.register(Station)
class StationAdmin(admin.ModelAdmin):
Nicolas Noé's avatar
Nicolas Noé committed
58
59
    list_display = ('name', 'expedition')
    list_filter = ('expedition', )
60
61
62
63
64

@admin.register(Expedition)
class ExpeditionAdmin(admin.ModelAdmin):
    pass

65
66
@admin.register(SpecimenPicture)
class SpecimenPictureAdmin(admin.ModelAdmin):
Nicolas Noé's avatar
Nicolas Noé committed
67
    fields = ('specimen', 'image', 'high_interest')
68
69

admin.site.site_header = 'Astapor administration'