Update admin page

This commit is contained in:
cuom1999 2022-06-12 13:52:02 +07:00
parent 56a147191d
commit 0b6031eef7
2 changed files with 1 additions and 29 deletions

View file

@ -1,5 +1,4 @@
from operator import attrgetter from operator import attrgetter
import statistics
from django import forms from django import forms
from django.contrib import admin from django.contrib import admin
@ -197,10 +196,6 @@ class ProblemAdmin(CompareVersionAdmin):
"name", "name",
"show_authors", "show_authors",
"points", "points",
"vote_cnt",
"vote_mean",
"vote_median",
"vote_std",
"is_public", "is_public",
"show_public", "show_public",
] ]
@ -295,11 +290,6 @@ class ProblemAdmin(CompareVersionAdmin):
def get_queryset(self, request): def get_queryset(self, request):
queryset = Problem.objects.prefetch_related("authors__user") queryset = Problem.objects.prefetch_related("authors__user")
queryset = queryset.annotate(
_vote_mean=Avg("problem_points_votes__points"),
_vote_std=StdDev("problem_points_votes__points"),
_vote_cnt=Count("problem_points_votes__points"),
)
if request.user.has_perm("judge.edit_all_problem"): if request.user.has_perm("judge.edit_all_problem"):
return queryset return queryset
@ -347,25 +337,6 @@ class ProblemAdmin(CompareVersionAdmin):
request, form, *args, **kwargs request, form, *args, **kwargs
) )
def vote_mean(self, obj):
return round(obj._vote_mean, 1) if obj._vote_mean is not None else None
vote_mean.admin_order_field = "_vote_mean"
def vote_std(self, obj):
return round(obj._vote_std, 1) if obj._vote_std is not None else None
vote_std.admin_order_field = "_vote_std"
def vote_cnt(self, obj):
return obj._vote_cnt
vote_cnt.admin_order_field = "_vote_cnt"
def vote_median(self, obj):
votes = obj.problem_points_votes.values_list("points", flat=True)
return statistics.median(votes) if votes else None
class ProblemPointsVoteAdmin(admin.ModelAdmin): class ProblemPointsVoteAdmin(admin.ModelAdmin):
list_display = ( list_display = (

View file

@ -69,4 +69,5 @@ revisions.register(ProblemData)
revisions.register(ProblemTestCase) revisions.register(ProblemTestCase)
revisions.register(ContestParticipation) revisions.register(ContestParticipation)
revisions.register(Rating) revisions.register(Rating)
revisions.register(VolunteerProblemVote)
del revisions del revisions