Add median to problem admin
This commit is contained in:
parent
891e2b0d92
commit
34523ab53f
1 changed files with 9 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
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
|
||||||
|
@ -132,7 +133,7 @@ class ProblemAdmin(VersionAdmin):
|
||||||
(_('Justice'), {'fields': ('banned_users',)}),
|
(_('Justice'), {'fields': ('banned_users',)}),
|
||||||
(_('History'), {'fields': ('change_message',)}),
|
(_('History'), {'fields': ('change_message',)}),
|
||||||
)
|
)
|
||||||
list_display = ['code', 'name', 'show_authors', 'points', 'vote_cnt', 'vote_mean', 'vote_std', 'is_public', 'show_public']
|
list_display = ['code', 'name', 'show_authors', 'points', 'vote_cnt', 'vote_mean', 'vote_median', 'vote_std', 'is_public', 'show_public']
|
||||||
ordering = ['code']
|
ordering = ['code']
|
||||||
search_fields = ('code', 'name', 'authors__user__username', 'curators__user__username')
|
search_fields = ('code', 'name', 'authors__user__username', 'curators__user__username')
|
||||||
inlines = [LanguageLimitInline, ProblemClarificationInline, ProblemSolutionInline, ProblemTranslationInline]
|
inlines = [LanguageLimitInline, ProblemClarificationInline, ProblemSolutionInline, ProblemTranslationInline]
|
||||||
|
@ -255,6 +256,10 @@ class ProblemAdmin(VersionAdmin):
|
||||||
return obj._vote_cnt
|
return obj._vote_cnt
|
||||||
vote_cnt.admin_order_field = '_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 = ('vote_points', 'voter', 'voter_rating', 'voter_point', 'problem_name', 'problem_code', 'problem_points')
|
list_display = ('vote_points', 'voter', 'voter_rating', 'voter_point', 'problem_name', 'problem_code', 'problem_points')
|
||||||
|
@ -266,6 +271,9 @@ class ProblemPointsVoteAdmin(admin.ModelAdmin):
|
||||||
return request.user.has_perm('judge.edit_own_problem')
|
return request.user.has_perm('judge.edit_own_problem')
|
||||||
return obj.problem.is_editable_by(request.user)
|
return obj.problem.is_editable_by(request.user)
|
||||||
|
|
||||||
|
def lookup_allowed(self, key, value):
|
||||||
|
return True
|
||||||
|
|
||||||
def problem_code(self, obj):
|
def problem_code(self, obj):
|
||||||
return obj.problem.code
|
return obj.problem.code
|
||||||
problem_code.short_description = _('Problem code')
|
problem_code.short_description = _('Problem code')
|
||||||
|
|
Loading…
Reference in a new issue