You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.1 KiB
84 lines
3.1 KiB
from django.contrib import admin
|
|
from unfold.admin import ModelAdmin, TabularInline
|
|
from unfold.decorators import display
|
|
from apps.events.models import Event, EventRegistration, RegistrationStatus, EventCategory, LocationType
|
|
|
|
|
|
class EventRegistrationInline(TabularInline):
|
|
model = EventRegistration
|
|
extra = 0
|
|
fields = ('user', 'status', 'notes', 'registered_at')
|
|
readonly_fields = ('registered_at',)
|
|
|
|
|
|
@admin.register(Event)
|
|
class EventAdmin(ModelAdmin):
|
|
list_display = (
|
|
'title',
|
|
'organizer',
|
|
'display_category',
|
|
'event_date',
|
|
'start_time',
|
|
'display_location_type',
|
|
'registration_status_badge',
|
|
'is_active',
|
|
'is_featured',
|
|
)
|
|
list_filter = ('category', 'location_type', 'is_active', 'is_featured', 'language', 'event_date')
|
|
search_fields = ('title', 'description', 'speaker_name', 'organizer__name', 'venue_address')
|
|
prepopulated_fields = {'slug': ('title',)}
|
|
inlines = [EventRegistrationInline]
|
|
actions = ['mark_as_featured', 'activate_events', 'deactivate_events']
|
|
|
|
@display(description="Category", label=True)
|
|
def display_category(self, obj):
|
|
color_map = {
|
|
EventCategory.RELIGIOUS: "purple",
|
|
EventCategory.EDUCATIONAL: "blue",
|
|
EventCategory.CULTURAL: "green",
|
|
EventCategory.COUNSELING: "amber",
|
|
EventCategory.CONFERENCE: "indigo",
|
|
EventCategory.WORKSHOP: "teal",
|
|
}
|
|
return obj.get_category_display(), color_map.get(obj.category, "gray")
|
|
|
|
@display(description="Type", label=True)
|
|
def display_location_type(self, obj):
|
|
color_map = {
|
|
LocationType.IN_PERSON: "blue",
|
|
LocationType.ONLINE: "green",
|
|
LocationType.HYBRID: "purple",
|
|
}
|
|
return obj.get_location_type_display(), color_map.get(obj.location_type, "gray")
|
|
|
|
@display(description="Registrations")
|
|
def registration_status_badge(self, obj):
|
|
return f"{obj.registration_count} / {obj.capacity}"
|
|
|
|
@admin.action(description="Mark selected events as Featured")
|
|
def mark_as_featured(self, request, queryset):
|
|
queryset.update(is_featured=True)
|
|
|
|
@admin.action(description="Activate selected events")
|
|
def activate_events(self, request, queryset):
|
|
queryset.update(is_active=True)
|
|
|
|
@admin.action(description="Deactivate selected events")
|
|
def deactivate_events(self, request, queryset):
|
|
queryset.update(is_active=False)
|
|
|
|
|
|
@admin.register(EventRegistration)
|
|
class EventRegistrationAdmin(ModelAdmin):
|
|
list_display = ('event', 'user', 'display_status', 'registered_at')
|
|
list_filter = ('status', 'registered_at')
|
|
search_fields = ('event__title', 'user__email', 'user__fullname', 'notes')
|
|
|
|
@display(description="Status", label=True)
|
|
def display_status(self, obj):
|
|
color_map = {
|
|
RegistrationStatus.REGISTERED: "green",
|
|
RegistrationStatus.ATTENDED: "blue",
|
|
RegistrationStatus.CANCELLED: "red",
|
|
}
|
|
return obj.get_status_display(), color_map.get(obj.status, "gray")
|