Ultron/ultron/objective/admin.py

166 lines
3.9 KiB
Python
Raw Normal View History

2021-12-09 16:53:44 +01:00
from django.contrib import admin
2022-01-09 21:48:37 +01:00
# from django_extensions.admin import ForeignKeyAutocompleteAdmin
2021-12-09 16:53:44 +01:00
2022-01-08 15:55:33 +01:00
from django_admin_listfilter_dropdown.filters import (
DropdownFilter,
ChoiceDropdownFilter,
RelatedDropdownFilter
)
2022-01-07 18:08:39 +01:00
from .models import TouchPosition, Skill, Routine, RoutineSkill
2021-12-09 16:53:44 +01:00
class TouchPositionAdmin(admin.ModelAdmin):
model = TouchPosition
2021-12-19 09:30:51 +01:00
list_display = ("long_label", "short_label", "allowed_in_competition", "is_default")
ordering = ("long_label", "short_label")
search_fields = ("long_label", "short_label")
list_filter = ("allowed_in_competition",)
2021-12-09 16:53:44 +01:00
2022-01-07 18:08:39 +01:00
def duplicate_skill(modeladmin, request, queryset): # pylint: disable=unused-argument
for obj in queryset:
obj.id = None
obj.save()
2021-12-09 16:53:44 +01:00
2022-01-09 21:48:37 +01:00
class SkillAdmin(admin.ModelAdmin):
2021-12-09 16:53:44 +01:00
model = Skill
fields = (
2021-12-19 09:30:51 +01:00
"long_label",
"short_label",
"informations",
"departure",
"landing",
"rotation_type",
"position",
"rotation",
"twist",
"difficulty",
"level",
"rank",
"notation",
"simplified_notation",
"is_competitive",
2022-01-08 11:40:10 +01:00
"age_boy_with_help",
"age_boy_without_help",
"age_boy_chained",
"age_boy_masterised",
"age_girl_with_help",
"age_girl_without_help",
"age_girl_chained",
"age_girl_masterised",
2021-12-19 09:30:51 +01:00
"prerequisites",
"educatives",
2021-12-09 16:53:44 +01:00
)
list_display = (
2021-12-19 09:30:51 +01:00
"long_label",
"difficulty",
"is_competitive",
"level",
"rank",
"notation",
2021-12-09 16:53:44 +01:00
)
2021-12-19 09:30:51 +01:00
ordering = ("long_label", "short_label")
search_fields = ("rank", "long_label", "short_label")
2021-12-09 16:53:44 +01:00
list_filter = (
2021-12-19 09:30:51 +01:00
"is_competitive",
2022-01-08 15:55:33 +01:00
('difficulty', DropdownFilter),
('departure', RelatedDropdownFilter),
('landing', RelatedDropdownFilter),
('level', DropdownFilter),
('rank', DropdownFilter),
'rotation_type',
('rotation', DropdownFilter),
2021-12-09 16:53:44 +01:00
)
2021-12-19 09:30:51 +01:00
filter_horizontal = ("educatives", "prerequisites")
2021-12-09 16:53:44 +01:00
2021-12-19 09:30:51 +01:00
duplicate_skill.short_description = "Duplicate selected record"
2021-12-09 16:53:44 +01:00
class Media:
2021-12-11 19:32:22 +01:00
js = (
2021-12-19 09:30:51 +01:00
"js/core/jquery-3.6.0.min.js",
"js/admin/skill.js",
2021-12-11 19:32:22 +01:00
)
2021-12-09 16:53:44 +01:00
class RoutineAdmin(admin.ModelAdmin):
model = Routine
fields = (
2021-12-19 09:30:51 +01:00
"long_label",
"short_label",
"difficulty",
"level",
"rank",
"educatives",
"prerequisites",
"age_boy_with_help",
"age_boy_without_help",
"age_boy_chained",
"age_boy_masterised",
"age_girl_with_help",
"age_girl_without_help",
"age_girl_chained",
"age_girl_masterised",
"is_active",
2021-12-19 09:30:51 +01:00
"is_competitive",
2021-12-09 16:53:44 +01:00
)
list_display = (
2021-12-19 09:30:51 +01:00
"long_label",
"short_label",
"is_competitive",
"is_active",
2021-12-19 09:30:51 +01:00
"level",
"rank",
"difficulty",
2021-12-09 16:53:44 +01:00
)
list_filter = (
('level', DropdownFilter),
"difficulty",
"is_competitive",
"is_active"
)
2021-12-09 16:53:44 +01:00
search_fields = (
2021-12-19 09:30:51 +01:00
"long_label",
"short_label",
2021-12-09 16:53:44 +01:00
)
2021-12-19 09:30:51 +01:00
filter_horizontal = ("educatives",)
2021-12-09 16:53:44 +01:00
2021-12-12 09:26:17 +01:00
class Media:
js = (
2021-12-19 09:30:51 +01:00
"js/core/jquery-3.6.0.min.js",
"js/admin/routine.js",
2021-12-12 09:26:17 +01:00
)
2021-12-09 16:53:44 +01:00
# TODO: ne proposer QUE les SKILL comme educatif
# def get_related_filter(self, model, request):
# # print('boum')
# if not issubclass(model, Educative):
# return super(Skill, self).get_related_filter(model, request)
class RoutineSkillAdmin(admin.ModelAdmin):
model = RoutineSkill
2021-12-19 09:30:51 +01:00
list_display = ("routine", "skill", "rank")
2021-12-09 16:53:44 +01:00
search_fields = (
2021-12-19 09:30:51 +01:00
"routine__long_label",
"routine__short_label",
2021-12-09 16:53:44 +01:00
)
2021-12-19 09:30:51 +01:00
ordering = ("routine",)
2022-01-09 21:48:37 +01:00
autocomplete_fields = ("routine", "skill")
2021-12-09 16:53:44 +01:00
admin.site.register(TouchPosition, TouchPositionAdmin)
admin.site.register(Skill, SkillAdmin)
admin.site.register(Routine, RoutineAdmin)
2022-01-07 18:08:39 +01:00
admin.site.register(RoutineSkill, RoutineSkillAdmin)