Ultron/ultron/objective/admin.py

159 lines
3.6 KiB
Python
Raw Normal View History

2021-12-09 16:53:44 +01:00
from django.contrib import admin
2021-12-19 09:30:51 +01:00
from .models import Educative, TouchPosition, Skill, Routine, RoutineSkill, Plan
2021-12-09 16:53:44 +01:00
from django_extensions.admin import ForeignKeyAutocompleteAdmin
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
def duplicate_skill(self, SkillAdmin, request, queryset):
for object in queryset:
object.id = None
object.save()
class SkillAdmin(ForeignKeyAutocompleteAdmin):
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",
"age_boy",
"age_girl",
"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",
"age_boy",
"age_girl",
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",
"departure",
"landing",
"rotation_type",
"rank",
"rotation",
"level",
"difficulty",
"age_boy",
"age_girl",
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",
"age_girl",
"active",
"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",
"active",
"level",
"rank",
"difficulty",
2021-12-09 16:53:44 +01:00
)
2021-12-19 09:30:51 +01:00
list_filter = ("level", "difficulty", "is_competitive", "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",)
2021-12-09 16:53:44 +01:00
class PlanAdmin(admin.ModelAdmin):
model = Plan
2021-12-19 09:30:51 +01:00
list_display = ("gymnast", "date", "educative")
list_filter = ("gymnast",)
search_fields = (
2021-12-19 09:30:51 +01:00
"gymnast__firstname",
"gymnast__lastname",
"educative__long_label",
"educative__short_label",
)
2021-12-18 22:40:15 +01:00
2021-12-09 16:53:44 +01:00
admin.site.register(TouchPosition, TouchPositionAdmin)
admin.site.register(Skill, SkillAdmin)
admin.site.register(Routine, RoutineAdmin)
admin.site.register(RoutineSkill, RoutineSkillAdmin)
2021-12-19 09:30:51 +01:00
admin.site.register(Plan, PlanAdmin)