mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 02:11:08 -05:00
- Cleaned up and standardized assertions in ApiTestMixin for API response validation. - Updated ASGI settings to use os.environ for setting the DJANGO_SETTINGS_MODULE. - Removed unused imports and improved formatting in settings.py. - Refactored URL patterns in urls.py for better readability and organization. - Enhanced view functions in views.py for consistency and clarity. - Added .flake8 configuration for linting and style enforcement. - Introduced type stubs for django-environ to improve type checking with Pylance.
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from django.contrib import admin
|
|
from django.utils.html import format_html
|
|
from .models import SlugHistory
|
|
|
|
|
|
@admin.register(SlugHistory)
|
|
class SlugHistoryAdmin(admin.ModelAdmin):
|
|
list_display = ["content_object_link", "old_slug", "created_at"]
|
|
list_filter = ["content_type", "created_at"]
|
|
search_fields = ["old_slug", "object_id"]
|
|
readonly_fields = ["content_type", "object_id", "old_slug", "created_at"]
|
|
date_hierarchy = "created_at"
|
|
ordering = ["-created_at"]
|
|
|
|
def content_object_link(self, obj):
|
|
"""Create a link to the related object's admin page"""
|
|
try:
|
|
url = obj.content_object.get_absolute_url()
|
|
return format_html('<a href="{}">{}</a>', url, str(obj.content_object))
|
|
except (AttributeError, ValueError):
|
|
return str(obj.content_object)
|
|
|
|
content_object_link.short_description = "Object"
|
|
|
|
def has_add_permission(self, request):
|
|
"""Disable manual creation of slug history records"""
|
|
return False
|
|
|
|
def has_change_permission(self, request, obj=None):
|
|
"""Disable editing of slug history records"""
|
|
return False
|