Skip to content
Merged
Show file tree
Hide file tree
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
41 changes: 20 additions & 21 deletions server/api/match/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,14 @@

from django.contrib import admin
from .models import Match, Team, MatchResult
import nested_admin


@admin.register(Match)
class MatchAdmin(admin.ModelAdmin):
list_display = ('match_name', 'match_date', 'group_id', 'stage_id')
search_fields = ('match_name',)
list_filter = ('group_id', 'stage_id')


@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
list_display = ('team_name', 'created_at')
search_fields = ('team_name',)
list_filter = ('created_at',)


@admin.register(MatchResult)
class MatchResultAdmin(admin.ModelAdmin):
list_display = (
'match', 'team', 'white_pins', 'penalty_pins', 'yellow_cards', 'red_cards',
'p1_position', 'p2_position', 'honor_point', 'point', 'completed_time_second'
)
exclude = ('honor_point', 'point')
class MatchResultInline(nested_admin.NestedTabularInline):
model = MatchResult
extra = 4 # 4 match results by default
max_num = 5
readonly_fields = ('honor_point', 'point')
list_filter = ('match', 'team')
search_fields = ('match__match_name', 'team__team_name')

Expand All @@ -44,3 +29,17 @@ def save_model(self, request, obj, form, change):
obj.honor_point = self._get_honor_point(obj.p1_position, obj.p2_position)

super().save_model(request, obj, form, change) # Call the parent's save_model


class MatchAdmin(nested_admin.NestedModelAdmin):
inlines = [MatchResultInline]


admin.site.register(Match, MatchAdmin)


@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
list_display = ('team_name', 'created_at')
search_fields = ('team_name',)
list_filter = ('created_at',)
3 changes: 3 additions & 0 deletions server/api/match/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class Match(models.Model):
def __str__(self):
return self.match_name

class Meta:
verbose_name_plural = "matches"


class Team(models.Model):
team_id = models.AutoField(primary_key=True)
Expand Down
1 change: 1 addition & 0 deletions server/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"django_extensions",
"rest_framework",
"corsheaders",
"nested_admin",
"api.healthcheck",
"api.match",
"api.sponsor.apps.SponsorConfig",
Expand Down
3 changes: 2 additions & 1 deletion server/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
"""

from django.contrib import admin
from django.urls import path, include
from django.urls import path, include, re_path
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
re_path(r'^_nested_admin/', include('nested_admin.urls')),
path("api/healthcheck/", include(("api.healthcheck.urls"))),
path("api/match/", include(("api.match.urls"))),
path("api/sponsor/", include(("api.sponsor.urls"))),
Expand Down
31 changes: 30 additions & 1 deletion server/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gunicorn = "^23.0.0"
python-dotenv = "^1.0.1"
django-extensions = "^3.2.3"
Pillow = ">=10.0.0"
django-nested-admin = "^4.1.1"


[tool.poetry.group.dev.dependencies]
Expand Down