This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apps/contests): improve the admin page
- Loading branch information
1 parent
dd58307
commit 47e9402
Showing
1 changed file
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}, | ||
), | ||
] |