summaryrefslogtreecommitdiff
path: root/app/birds/admin.py
blob: df0951ae55b163bdc7e555ddc8aa4a600e9cd9c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from django.contrib import admin
from django.contrib.gis.admin import OSMGeoAdmin
from birds.models import BirdSighting, BirdAudio, BirdClass, Bird, APClass, AP, Sighting

from photos.forms import GalleryForm
from utils.util import get_latlon
from utils.widgets import CustomSelectMultiple


class GalleryFormPlus(GalleryForm):
    def __init__(self, *args, **kwargs):
        super(GalleryFormPlus, self).__init__(*args, **kwargs)
        self.base_fields['seen_by'].widget = CustomSelectMultiple()
    
    class Meta:
        model = Sighting
        fields = '__all__' 


@admin.register(APClass)
class APClassAdmin(admin.ModelAdmin):
    list_display = ('common_name', 'scientific_name', 'kind')
    list_filter = ('kind',)


@admin.register(AP)
class APAdmin(admin.ModelAdmin):
    list_display = ('pk', 'common_name', 'scientific_name', 'kind', 'code', 'apclass')
    list_filter = ('apclass__kind','apclass')


@admin.register(Sighting)
class SightingAdmin(OSMGeoAdmin):
    form = GalleryFormPlus
    list_filter = ('seen_by',('location', admin.RelatedOnlyFieldListFilter),)
    list_display = ('ap', 'location')
    # options for OSM map Using custom ESRI topo map
    lat, lon = get_latlon()
    default_lon = lon
    default_lat = lat
    default_zoom = 13
    units = True
    scrollable = False
    map_width = 700
    map_height = 425
    map_template = 'gis/admin/osm.html'
    openlayers_url = '/static/admin/js/OpenLayers.js'


class BirdClassAdmin(admin.ModelAdmin):
    list_display = ('common_name', 'scientific_name',)


class BirdAudioAdmin(admin.ModelAdmin):
    list_display = ('bird', 'recorder',)


class BirdAdmin(admin.ModelAdmin):
    list_display = ('pk', 'common_name', 'scientific_name', 'code', 'bird_class')
    list_filter = ('bird_class',)

class BirdSightingAdmin(OSMGeoAdmin):
    form = GalleryFormPlus
    list_filter = (
    )
    list_display = ('bird', 'location')
    list_filter = ('seen_by',('location', admin.RelatedOnlyFieldListFilter),)
    fieldsets = (
        ('Sighting', {
            'fields': (
                'bird',
                'point',
                'date',
                'seen_by',
                'images',
                'audio',
            ),
            'classes': (
                'show',
                'extrapretty',
                'wide'
            )
        }
        ),
    )
    # options for OSM map Using custom ESRI topo map
    lat, lon = get_latlon()
    default_lon = lon
    default_lat = lat
    default_zoom = 13
    units = True
    scrollable = False
    map_width = 700
    map_height = 425
    map_template = 'gis/admin/osm.html'
    openlayers_url = '/static/admin/js/OpenLayers.js'

admin.site.register(BirdSighting, BirdSightingAdmin)
admin.site.register(BirdClass, BirdClassAdmin)
admin.site.register(BirdAudio, BirdAudioAdmin)
admin.site.register(Bird, BirdAdmin)