67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
from django.contrib import admin
|
|
from django_mptt_admin.admin import DjangoMpttAdmin
|
|
|
|
from .models import Box, BoxType, Thing, ThingFile, ThingLink, ThingType
|
|
|
|
|
|
@admin.register(BoxType)
|
|
class BoxTypeAdmin(admin.ModelAdmin):
|
|
"""Admin configuration for BoxType model."""
|
|
|
|
list_display = ('name', 'width', 'height', 'length')
|
|
search_fields = ('name',)
|
|
|
|
|
|
@admin.register(Box)
|
|
class BoxAdmin(admin.ModelAdmin):
|
|
"""Admin configuration for Box model."""
|
|
|
|
list_display = ('id', 'box_type')
|
|
list_filter = ('box_type',)
|
|
search_fields = ('id',)
|
|
|
|
|
|
@admin.register(ThingType)
|
|
class ThingTypeAdmin(DjangoMpttAdmin):
|
|
"""Admin configuration for ThingType model."""
|
|
|
|
search_fields = ('name',)
|
|
|
|
|
|
@admin.register(Thing)
|
|
class ThingAdmin(admin.ModelAdmin):
|
|
"""Admin configuration for Thing model."""
|
|
|
|
list_display = ('name', 'thing_type', 'box')
|
|
list_filter = ('thing_type', 'box')
|
|
search_fields = ('name', 'description')
|
|
|
|
|
|
class ThingFileInline(admin.TabularInline):
|
|
"""Inline admin for Thing files."""
|
|
|
|
model = ThingFile
|
|
extra = 1
|
|
fields = ('title', 'file')
|
|
|
|
|
|
class ThingLinkInline(admin.TabularInline):
|
|
"""Inline admin for Thing links."""
|
|
|
|
model = ThingLink
|
|
extra = 1
|
|
fields = ('title', 'url')
|
|
|
|
|
|
class ThingAdminWithFiles(admin.ModelAdmin):
|
|
"""Admin configuration for Thing model with files and links."""
|
|
|
|
list_display = ('name', 'thing_type', 'box')
|
|
list_filter = ('thing_type', 'box')
|
|
search_fields = ('name', 'description')
|
|
inlines = [ThingFileInline, ThingLinkInline]
|
|
|
|
|
|
admin.site.unregister(Thing)
|
|
admin.register(Thing, ThingAdminWithFiles)
|