from django.contrib import admin from django import forms from dal import autocomplete from leaflet.admin import LeafletGeoAdmin from .models import CaseStudy, CaseStudyDraft, SpatialRefSys, PointOfInterest class CaseStudyDraftAdmin(admin.ModelAdmin): model = CaseStudyDraft class CaseStudyAdminForm(forms.ModelForm): class Meta: model = CaseStudy widgets = { 'coordinate_reference_system': autocomplete.ModelSelect2( url='srs-autocomplete' ) } fields = '__all__' class CaseStudyAdmin(LeafletGeoAdmin): list_display = ('id', 'date_created', 'entry_name', 'approved') actions = ['approve', 'unapprove'] form = CaseStudyAdminForm def approve(self, request, queryset): updated = queryset.update(approved=True) if updated == 1: message_bit = "1 case study was" else: message_bit = "{0} case studies were".format(updated) self.message_user(request, "{0} successfully approved".format( message_bit )) approve.short_description = "Approve selected case studies" def unapprove(self, request, queryset): updated = queryset.update(approved=False) if updated == 1: message_bit = "1 case study was" else: message_bit = "{0} case studies were".format(updated) self.message_user(request, "{0} successfully un-approved".format( message_bit )) unapprove.short_description = "Un-approve selected case studies" admin.site.register(CaseStudy, CaseStudyAdmin) admin.site.register(SpatialRefSys) admin.site.register(CaseStudyDraft, CaseStudyDraftAdmin) admin.site.register(PointOfInterest)