162 lines
3.6 KiB
Python
162 lines
3.6 KiB
Python
|
|
from django.contrib import admin
|
|
|
|
from .models import (
|
|
Educative,
|
|
TouchPosition,
|
|
Skill,
|
|
Routine,
|
|
RoutineSkill,
|
|
Chrono,
|
|
)
|
|
from django_extensions.admin import ForeignKeyAutocompleteAdmin
|
|
|
|
|
|
class TouchPositionAdmin(admin.ModelAdmin):
|
|
model = TouchPosition
|
|
|
|
list_display = ("label", "short_label", "allowed_in_competition", "is_default")
|
|
ordering = ("label", "short_label")
|
|
search_fields = ("label", "short_label")
|
|
list_filter = ("allowed_in_competition",)
|
|
|
|
|
|
def duplicate_skill(self, SkillAdmin, request, queryset):
|
|
for object in queryset:
|
|
object.id = None
|
|
object.save()
|
|
|
|
|
|
class SkillAdmin(ForeignKeyAutocompleteAdmin):
|
|
model = Skill
|
|
|
|
fields = (
|
|
"long_label",
|
|
"short_label",
|
|
"information",
|
|
"departure",
|
|
"landing",
|
|
"rotation_type",
|
|
"position",
|
|
"rotation",
|
|
"twist",
|
|
"difficulty",
|
|
"level",
|
|
"rank",
|
|
"notation",
|
|
"simplified_notation",
|
|
"is_competitive",
|
|
"age_boy",
|
|
"age_girl",
|
|
"prerequisites",
|
|
"educatives",
|
|
)
|
|
|
|
list_display = (
|
|
"long_label",
|
|
"difficulty",
|
|
"is_competitive",
|
|
"level",
|
|
"rank",
|
|
"notation",
|
|
"age_boy",
|
|
"age_girl",
|
|
)
|
|
|
|
ordering = ("long_label", "short_label")
|
|
search_fields = ("rank", "long_label", "short_label")
|
|
list_filter = (
|
|
"is_competitive",
|
|
"departure",
|
|
"landing",
|
|
"rotation_type",
|
|
"rank",
|
|
"rotation",
|
|
"level",
|
|
"difficulty",
|
|
"age_boy",
|
|
"age_girl",
|
|
)
|
|
|
|
filter_horizontal = ("educatives", "prerequisites")
|
|
|
|
duplicate_skill.short_description = "Duplicate selected record"
|
|
|
|
class Media:
|
|
js = ("js/skill.js",)
|
|
|
|
|
|
class RoutineAdmin(admin.ModelAdmin):
|
|
model = Routine
|
|
|
|
fields = (
|
|
"long_label",
|
|
"short_label",
|
|
"difficulty",
|
|
"level",
|
|
"rank",
|
|
"educatives",
|
|
"prerequisites",
|
|
"age_boy",
|
|
"age_girl",
|
|
"active",
|
|
"is_competitive",
|
|
)
|
|
list_display = (
|
|
"long_label",
|
|
"short_label",
|
|
"is_competitive",
|
|
"active",
|
|
"level",
|
|
"rank",
|
|
"difficulty",
|
|
)
|
|
list_filter = ("level", "difficulty", "is_competitive", "active")
|
|
search_fields = (
|
|
"long_label",
|
|
"short_label",
|
|
)
|
|
|
|
filter_horizontal = ("educatives",)
|
|
|
|
class Media:
|
|
js = ("js/routine.js",)
|
|
|
|
# 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
|
|
|
|
list_display = ("routine", "skill", "rank")
|
|
search_fields = (
|
|
"routine__label",
|
|
"routine__short_label",
|
|
)
|
|
ordering = ("routine",)
|
|
|
|
|
|
class ChronoAdmin(ForeignKeyAutocompleteAdmin):
|
|
model = Chrono
|
|
|
|
list_display = ("date", "gymnast", "routine", "score")
|
|
# search_fields = ('gymnast', 'routine')
|
|
autocomplete_fields = ["gymnast", "routine"]
|
|
|
|
related_search_fields = {
|
|
"gymnast": ("lastname", "firstname"),
|
|
"routine": ("label", "short_label"),
|
|
}
|
|
|
|
|
|
# admin.site.register(Educative) # a commenter je crois
|
|
admin.site.register(TouchPosition, TouchPositionAdmin)
|
|
admin.site.register(Skill, SkillAdmin)
|
|
admin.site.register(Routine, RoutineAdmin)
|
|
admin.site.register(RoutineSkill, RoutineSkillAdmin)
|
|
admin.site.register(Chrono, ChronoAdmin)
|