from django.contrib import admin

from apps.activities.models import Activity, ActionType  

# Registering the Activity model and its customized admin interface
@admin.register(Activity)
class ActivityAdmin(admin.ModelAdmin):
    """Customizing the Activity model in the Django admin."""
    
    # Displaying fields in the list view of admin interface
    list_display = ("performer", "action_type", "timestamp", "details", "related_object_id", "related_object_type")
    
    # Adding filters for the admin interface
    list_filter = ("action_type", "timestamp", "performer")
    
    # Search functionality in admin interface
    search_fields = ("performer__email", "action_type", "details", "related_object_type")
    
    # Pagination in admin interface
    list_per_page = 25
    
    # Ordering of records
    ordering = ["-timestamp"]

    # Fields to be displayed in detail view of each record
    fieldsets = (
        ("Activity Details", {
            "fields": ("performer","action_type", "details",),
        }),
        ("Additional Information", {
            "classes": ("collapse",),
            "fields": ( "timestamp", "related_object_id", "related_object_type",),
        }),
    )
    # Specify read-only fields
    readonly_fields = ("timestamp", "related_object_id", "related_object_type",)