mpeltriaux
5b0b376405
* 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
126 lines
2.9 KiB
Python
126 lines
2.9 KiB
Python
from django.contrib import admin
|
|
|
|
from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \
|
|
EcoAccountDeduction, EcoAccount
|
|
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):
|
|
list_display = [
|
|
"id",
|
|
"biotope_type",
|
|
"surface",
|
|
]
|
|
|
|
|
|
class CompensationActionAdmin(admin.ModelAdmin):
|
|
list_display = [
|
|
"id",
|
|
"action_type",
|
|
"amount",
|
|
"unit",
|
|
"comment",
|
|
]
|
|
|
|
|
|
admin.site.register(Compensation, CompensationAdmin)
|
|
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) |