Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat(apps/contests): improve the admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterteriyaki committed Oct 1, 2023
1 parent dd58307 commit 47e9402
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions apps/contests/admin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,47 @@
from typing import TYPE_CHECKING

from django.contrib.admin import ModelAdmin, register
from django.forms import (
CharField,
ModelForm,
ModelMultipleChoiceField,
Textarea,
)
from django.utils.translation import gettext_lazy as _

from apps.contests.models import Contest
from apps.users.models import User

if TYPE_CHECKING:
ContestAdminBase = ModelAdmin[Contest]
ContestModelFormBase = ModelForm[Contest]
else:
ContestAdminBase = ModelAdmin
ContestModelFormBase = ModelForm


class ContestModelForm(ContestModelFormBase):
description = CharField(widget=Textarea(attrs={"rows": 14, "cols": 80}))
users = ModelMultipleChoiceField(
queryset=User.objects.all(), required=False
)

class Meta:
model = Contest
fields = "__all__"


@register(Contest)
class ContestAdmin(ContestAdminBase):
list_display = ("title", "start_time", "status")
form = ContestModelForm

list_display = ("title", "start_time", "end_time", "status")
list_filter = ("start_time", "end_time")

fieldsets = [
(_("General"), {"fields": ("title", "description")}),
(_("Other"), {"fields": ("start_time", "end_time", "users")}),
(
_("Other"),
{"fields": ("start_time", "end_time", "users", "cancelled")},
),
]

0 comments on commit 47e9402

Please sign in to comment.