from django.contrib import admin
from django.utils.html import format_html
from .models import InvitationCode


@admin.register(InvitationCode)
class InvitationCodeAdmin(admin.ModelAdmin):
    list_display = ['code', 'created_at', 'expires_at', 'is_used', 'used_by']
    list_filter = ['is_used', 'created_at']
    search_fields = ['code']
    readonly_fields = ['code', 'created_at']

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        qs = qs.select_related('used_by', 'created_by')
        return qs