mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 10:51:09 -05:00
here we go
This commit is contained in:
@@ -1,19 +1,49 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from simple_history.admin import SimpleHistoryAdmin
|
||||
from .models import Park, ParkArea
|
||||
|
||||
@admin.register(Park)
|
||||
class ParkAdmin(SimpleHistoryAdmin):
|
||||
list_display = ('name', 'location', 'owner', 'status', 'opening_date')
|
||||
list_filter = ('status', 'owner')
|
||||
list_display = ('name', 'location', 'status', 'owner', 'created_at', 'updated_at')
|
||||
list_filter = ('status', 'country', 'region', 'city')
|
||||
search_fields = ('name', 'location', 'description')
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
readonly_fields = ('id', 'created_at', 'updated_at')
|
||||
|
||||
@admin.register(ParkArea)
|
||||
def get_history_list_display(self, request):
|
||||
"""Customize the list display for history records"""
|
||||
return ('name', 'location', 'status', 'history_date', 'history_user')
|
||||
|
||||
class ParkAreaAdmin(SimpleHistoryAdmin):
|
||||
list_display = ('name', 'park', 'opening_date')
|
||||
list_display = ('name', 'park', 'created_at', 'updated_at')
|
||||
list_filter = ('park',)
|
||||
search_fields = ('name', 'description')
|
||||
search_fields = ('name', 'description', 'park__name')
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
prepopulated_fields = {'slug': ('name',)}
|
||||
readonly_fields = ('id', 'created_at', 'updated_at')
|
||||
|
||||
def get_history_list_display(self, request):
|
||||
"""Customize the list display for history records"""
|
||||
return ('name', 'park', 'history_date', 'history_user')
|
||||
|
||||
# Register the models with their admin classes
|
||||
admin.site.register(Park, ParkAdmin)
|
||||
admin.site.register(ParkArea, ParkAreaAdmin)
|
||||
|
||||
# Register the historical records for direct editing
|
||||
from simple_history.models import HistoricalRecords
|
||||
from .models import Park
|
||||
|
||||
class HistoricalParkAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'location', 'status', 'history_date', 'history_user', 'history_type')
|
||||
list_filter = ('status', 'country', 'region', 'city', 'history_type')
|
||||
search_fields = ('name', 'location', 'description')
|
||||
readonly_fields = ('history_date', 'history_type', 'history_id')
|
||||
|
||||
def has_add_permission(self, request):
|
||||
return False # Prevent adding new historical records directly
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return False # Prevent deleting historical records
|
||||
|
||||
# Register the historical model
|
||||
admin.site.register(Park.history.model, HistoricalParkAdmin)
|
||||
|
||||
Reference in New Issue
Block a user