#99 Admin backend cleanup
* removes admin backend views which are not important for production * adds filtering functionalities on index views * simplifies detail views on intervention, compensation, ecoaccount and ema * adds autocomplete fields on detail views * adds handy horizontal filter fields on detail views
This commit is contained in:
@@ -2,7 +2,100 @@ from django.contrib import admin
|
||||
|
||||
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
||||
EcoAccountDeduction, EcoAccount
|
||||
from konova.admin import BaseObjectAdmin
|
||||
from konova.admin import BaseObjectAdmin, BaseResourceAdmin
|
||||
|
||||
|
||||
class AbstractCompensationAdmin(BaseObjectAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"identifier",
|
||||
"title",
|
||||
"created",
|
||||
"deleted",
|
||||
]
|
||||
|
||||
def get_fields(self, request, obj=None):
|
||||
return super().get_fields(request, obj) + [
|
||||
"identifier",
|
||||
"title",
|
||||
"comment",
|
||||
"after_states",
|
||||
"before_states",
|
||||
]
|
||||
|
||||
def get_readonly_fields(self, request, obj=None):
|
||||
return super().get_readonly_fields(request, obj) + [
|
||||
"after_states",
|
||||
"before_states",
|
||||
]
|
||||
|
||||
|
||||
class CompensationAdmin(AbstractCompensationAdmin):
|
||||
autocomplete_fields = [
|
||||
"intervention",
|
||||
]
|
||||
|
||||
def get_fields(self, request, obj=None):
|
||||
return super().get_fields(request, obj) + [
|
||||
"is_cef",
|
||||
"is_coherence_keeping",
|
||||
"intervention",
|
||||
]
|
||||
|
||||
|
||||
class EcoAccountAdmin(AbstractCompensationAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"identifier",
|
||||
"title",
|
||||
"created",
|
||||
"deleted",
|
||||
]
|
||||
|
||||
filter_horizontal = [
|
||||
"users"
|
||||
]
|
||||
|
||||
def get_fields(self, request, obj=None):
|
||||
return super().get_fields(request, obj) + [
|
||||
"deductable_surface",
|
||||
"users"
|
||||
]
|
||||
|
||||
|
||||
class PaymentAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"amount",
|
||||
"due_on",
|
||||
]
|
||||
|
||||
|
||||
class EcoAccountDeductionAdmin(BaseResourceAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"account",
|
||||
"intervention",
|
||||
"surface",
|
||||
]
|
||||
search_fields = [
|
||||
"account__identifier",
|
||||
"account__title",
|
||||
"intervention__identifier",
|
||||
"intervention__title",
|
||||
"surface",
|
||||
]
|
||||
autocomplete_fields = [
|
||||
"account",
|
||||
"intervention",
|
||||
]
|
||||
|
||||
def get_fields(self, request, obj=None):
|
||||
return super().get_fields(request, obj) + [
|
||||
"account",
|
||||
"intervention",
|
||||
"surface",
|
||||
]
|
||||
|
||||
|
||||
class CompensationStateAdmin(admin.ModelAdmin):
|
||||
@@ -23,44 +116,11 @@ class CompensationActionAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
class CompensationAdmin(BaseObjectAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"identifier",
|
||||
"title",
|
||||
"created",
|
||||
"deleted",
|
||||
]
|
||||
|
||||
|
||||
class EcoAccountAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"identifier",
|
||||
"title",
|
||||
]
|
||||
|
||||
|
||||
class PaymentAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"amount",
|
||||
"due_on",
|
||||
]
|
||||
|
||||
|
||||
class EcoAccountDeductionAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"account",
|
||||
"intervention",
|
||||
"surface",
|
||||
]
|
||||
|
||||
|
||||
admin.site.register(Compensation, CompensationAdmin)
|
||||
admin.site.register(Payment, PaymentAdmin)
|
||||
admin.site.register(CompensationAction, CompensationActionAdmin)
|
||||
admin.site.register(CompensationState, CompensationStateAdmin)
|
||||
admin.site.register(EcoAccount, EcoAccountAdmin)
|
||||
admin.site.register(EcoAccountDeduction, EcoAccountDeductionAdmin)
|
||||
|
||||
# For a more cleaner admin interface these rarely used admin views are not important for deployment
|
||||
#admin.site.register(Payment, PaymentAdmin)
|
||||
#admin.site.register(CompensationAction, CompensationActionAdmin)
|
||||
#admin.site.register(CompensationState, CompensationStateAdmin)
|
||||
@@ -59,7 +59,7 @@ class CompensationAction(BaseResource):
|
||||
objects = CompensationActionManager()
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {} {}".format(self.action_type, self.amount, self.unit)
|
||||
return f"{self.action_type} | {self.amount} {self.unit}"
|
||||
|
||||
@property
|
||||
def unit_humanize(self):
|
||||
|
||||
@@ -46,7 +46,7 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
||||
objects = EcoAccountManager()
|
||||
|
||||
def __str__(self):
|
||||
return "{}".format(self.identifier)
|
||||
return f"{self.identifier} ({self.title})"
|
||||
|
||||
def clean(self):
|
||||
# Deductable surface can not be larger than added states after surface
|
||||
|
||||
@@ -44,4 +44,4 @@ class CompensationState(UuidModel):
|
||||
objects = CompensationStateManager()
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {} m²".format(self.biotope_type, self.surface)
|
||||
return f"{self.biotope_type} | {self.surface} m²"
|
||||
|
||||
Reference in New Issue
Block a user