22
33from django .contrib import admin
44from .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' ,)
0 commit comments