Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/apps/competitions/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from . import models


class privateCompetitionsFilter(admin.SimpleListFilter):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title = _("Private non-test")

# Parameter for the filter that will be used in the URL query.
parameter_name = "private"

def lookups(self, request, model_admin):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return [
("privateSmall", _("Submissions >= 25 and Participants >= 10")),
]

def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Only show private competitions with >= 25 submissions and >=10 participants
if self.value() == "privateSmall":
return queryset.filter(
published=False,
submissions_count__gte=10,
participants_count__gte=5
)


class CompetitionAdmin(admin.ModelAdmin):
search_fields = ['title', 'docker_image', 'created_by__username']
list_display = ['id', 'title', 'created_by', 'is_featured']
list_filter = ['is_featured']
list_filter = ['is_featured', privateCompetitionsFilter]


admin.site.register(models.Competition, CompetitionAdmin)
Expand Down