2022-01-24 22:03:10 -05:00
|
|
|
from django.contrib import admin
|
2022-02-18 15:33:03 -05:00
|
|
|
from django import forms
|
2022-01-24 22:03:10 -05:00
|
|
|
|
2022-02-16 16:06:51 -05:00
|
|
|
from .models import LockerBank, LockerInfo, LockerUnit
|
|
|
|
|
|
|
|
|
|
|
|
class LockerInfoInline(admin.TabularInline):
|
|
|
|
model = LockerInfo
|
|
|
|
extra = 0
|
2022-01-24 22:03:10 -05:00
|
|
|
|
2022-01-24 23:37:04 -05:00
|
|
|
|
2022-01-27 14:55:27 -05:00
|
|
|
class LockerUnitInline(admin.TabularInline):
|
|
|
|
model = LockerUnit
|
2022-01-24 22:03:10 -05:00
|
|
|
extra = 0
|
|
|
|
|
2022-01-24 23:37:04 -05:00
|
|
|
|
2022-01-24 22:03:10 -05:00
|
|
|
@admin.register(LockerBank)
|
|
|
|
class LockerBankAdmin(admin.ModelAdmin):
|
2022-01-27 14:55:27 -05:00
|
|
|
inlines = [LockerUnitInline]
|
2022-01-24 22:03:10 -05:00
|
|
|
prepopulated_fields = {"slug": ("name",)}
|
|
|
|
|
2022-01-24 23:37:04 -05:00
|
|
|
|
2022-01-27 14:55:27 -05:00
|
|
|
@admin.register(LockerUnit)
|
|
|
|
class LockerUnitAdmin(admin.ModelAdmin):
|
2022-02-16 16:06:51 -05:00
|
|
|
inlines = [LockerInfoInline]
|
2022-01-27 14:55:27 -05:00
|
|
|
|
|
|
|
|
2022-02-16 16:06:51 -05:00
|
|
|
@admin.register(LockerInfo)
|
|
|
|
class LockerInfoAdmin(admin.ModelAdmin):
|
|
|
|
search_fields = ["renter__username", "locker_unit__bank__name"]
|
|
|
|
list_filter = ["locker_unit__bank", "locker_unit", "renter"]
|
2022-02-18 15:35:03 -05:00
|
|
|
list_display = [
|
|
|
|
"locker_unit",
|
|
|
|
"address",
|
|
|
|
"blind_code",
|
|
|
|
"bitting_code",
|
|
|
|
"renter",
|
|
|
|
"notes",
|
|
|
|
]
|
2022-02-16 16:06:51 -05:00
|
|
|
list_display_links = ["locker_unit", "address"]
|
2022-02-18 15:33:03 -05:00
|
|
|
list_editable = ["blind_code", "bitting_code"]
|
2022-02-18 13:18:36 -05:00
|
|
|
|
|
|
|
def get_queryset(self, request):
|
|
|
|
return LockerInfo.objects.select_related("locker_unit", "locker_unit__bank")
|
2022-02-18 15:33:03 -05:00
|
|
|
|
|
|
|
def get_changelist_formset(self, request, **kwargs):
|
|
|
|
kwargs["widgets"] = {
|
|
|
|
"blind_code": forms.TextInput(attrs={"size": 6}),
|
|
|
|
"bitting_code": forms.TextInput(attrs={"size": 6}),
|
|
|
|
}
|
|
|
|
return super().get_changelist_formset(request, **kwargs)
|