Skip to content

Commit 9a6c32e

Browse files
authored
Merge pull request #53 from codersforcauses/issue-46-Admin_Improve_experience_of_entering_Match_Results
Issue 46 admin improve experience of entering match results
2 parents 5ab7a60 + b1b8b13 commit 9a6c32e

6 files changed

Lines changed: 57 additions & 23 deletions

File tree

server/api/match/admin.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,14 @@
22

33
from django.contrib import admin
44
from .models import Match, Team, MatchResult
5+
import nested_admin
56

67

7-
@admin.register(Match)
8-
class MatchAdmin(admin.ModelAdmin):
9-
list_display = ('match_name', 'match_date', 'group_id', 'stage_id')
10-
search_fields = ('match_name',)
11-
list_filter = ('group_id', 'stage_id')
12-
13-
14-
@admin.register(Team)
15-
class TeamAdmin(admin.ModelAdmin):
16-
list_display = ('team_name', 'created_at')
17-
search_fields = ('team_name',)
18-
list_filter = ('created_at',)
19-
20-
21-
@admin.register(MatchResult)
22-
class MatchResultAdmin(admin.ModelAdmin):
23-
list_display = (
24-
'match', 'team', 'white_pins', 'penalty_pins', 'yellow_cards', 'red_cards',
25-
'p1_position', 'p2_position', 'honor_point', 'point', 'completed_time_second'
26-
)
27-
exclude = ('honor_point', 'point')
8+
class MatchResultInline(nested_admin.NestedTabularInline):
9+
model = MatchResult
10+
extra = 4 # 4 match results by default
11+
max_num = 5
12+
readonly_fields = ('honor_point', 'point')
2813
list_filter = ('match', 'team')
2914
search_fields = ('match__match_name', 'team__team_name')
3015

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

4631
super().save_model(request, obj, form, change) # Call the parent's save_model
32+
33+
34+
class MatchAdmin(nested_admin.NestedModelAdmin):
35+
inlines = [MatchResultInline]
36+
37+
38+
admin.site.register(Match, MatchAdmin)
39+
40+
41+
@admin.register(Team)
42+
class TeamAdmin(admin.ModelAdmin):
43+
list_display = ('team_name', 'created_at')
44+
search_fields = ('team_name',)
45+
list_filter = ('created_at',)

server/api/match/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class Match(models.Model):
1111
def __str__(self):
1212
return self.match_name
1313

14+
class Meta:
15+
verbose_name_plural = "matches"
16+
1417

1518
class Team(models.Model):
1619
team_id = models.AutoField(primary_key=True)

server/api/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"django_extensions",
5252
"rest_framework",
5353
"corsheaders",
54+
"nested_admin",
5455
"api.healthcheck",
5556
"api.match",
5657
"api.sponsor.apps.SponsorConfig",

server/api/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
"""
1717

1818
from django.contrib import admin
19-
from django.urls import path, include
19+
from django.urls import path, include, re_path
2020
from django.conf import settings
2121
from django.conf.urls.static import static
2222

2323
urlpatterns = [
2424
path("admin/", admin.site.urls),
25+
re_path(r'^_nested_admin/', include('nested_admin.urls')),
2526
path("api/healthcheck/", include(("api.healthcheck.urls"))),
2627
path("api/match/", include(("api.match.urls"))),
2728
path("api/sponsor/", include(("api.sponsor.urls"))),

server/poetry.lock

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ gunicorn = "^23.0.0"
1717
python-dotenv = "^1.0.1"
1818
django-extensions = "^3.2.3"
1919
Pillow = ">=10.0.0"
20+
django-nested-admin = "^4.1.1"
2021

2122

2223
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)