128 lines
3.3 KiB
Python
128 lines
3.3 KiB
Python
"""Administration des gymnastes et des personnes.
|
|
|
|
Remarks:
|
|
* Je ne pense pas qu'il faille encore passer par `ForeignKeyAutocompleteAdmin`.
|
|
https://docs.djangoproject.com/fr/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields
|
|
"""
|
|
|
|
from django.contrib import admin
|
|
|
|
from django_extensions.admin import ForeignKeyAutocompleteAdmin
|
|
|
|
from .models import (
|
|
Gymnast,
|
|
Accident,
|
|
CanDoRelation,
|
|
ToDoRelation,
|
|
GymnastHasRoutine,
|
|
)
|
|
|
|
|
|
class CanDoRelationAdmin(ForeignKeyAutocompleteAdmin):
|
|
model = CanDoRelation
|
|
|
|
list_display = ("date", "gymnast", "educative")
|
|
list_filter = ("gymnast",)
|
|
search_fields = ("gymnast", "educative")
|
|
autocomplete_fields = ("gymnast",)
|
|
|
|
# related_search_fields = {
|
|
# 'gymnast': ('lastname', 'firstname'),
|
|
# }
|
|
|
|
|
|
class InlineCanDoRelation(admin.TabularInline):
|
|
model = CanDoRelation
|
|
|
|
|
|
class ToDoRelationAdmin(ForeignKeyAutocompleteAdmin):
|
|
model = ToDoRelation
|
|
|
|
list_display = ("date", "gymnast", "educative")
|
|
list_filter = ("gymnast",)
|
|
search_fields = ("gymnast", "educative")
|
|
autocomplete_fields = ("gymnast",)
|
|
|
|
# related_search_fields = {
|
|
# 'gymnast': ('lastname', 'firstname'),
|
|
# # 'educative': ('longLabel', 'shortLabel'), # TO_FRED : Pq ca marche pas ca ?
|
|
# }
|
|
|
|
|
|
class GymnastHasRoutineAdmin(ForeignKeyAutocompleteAdmin):
|
|
model = GymnastHasRoutine
|
|
|
|
list_display = ("gymnast", "routine", "routine_type", "datebegin", "dateend")
|
|
list_filter = ("gymnast", "routine_type")
|
|
search_fields = ("gymnast", "routine")
|
|
autocomplete_fields = ("gymnast", "routine")
|
|
|
|
|
|
class InlineToDoRelation(admin.TabularInline):
|
|
model = ToDoRelation
|
|
|
|
|
|
class GymnastAdmin(admin.ModelAdmin):
|
|
model = Gymnast
|
|
|
|
def lastname(self, obj):
|
|
return obj.user.last_name
|
|
|
|
def firstname(self, obj):
|
|
return obj.user.first_name
|
|
|
|
def email(self, obj):
|
|
return obj.user.email
|
|
|
|
def is_active(self, obj):
|
|
return obj.user.is_active
|
|
|
|
fields = (
|
|
# "lastname",
|
|
# "firstname",
|
|
"birthdate",
|
|
"gender",
|
|
"club",
|
|
"niss",
|
|
"address",
|
|
"postal",
|
|
"city",
|
|
"phone",
|
|
"gsm",
|
|
# "user__email",
|
|
"fedid",
|
|
"year_of_practice",
|
|
"gsm_mother",
|
|
"email_mother",
|
|
"gsm_father",
|
|
"email_father",
|
|
# "user.is_active",
|
|
"orientation",
|
|
"trainer",
|
|
"picture",
|
|
"content",
|
|
)
|
|
|
|
list_display = ("lastname", "firstname", "birthdate", "age", "is_active")
|
|
list_filter = ("gender", "user__is_active")
|
|
search_fields = ("lastname", "firstname", "email")
|
|
inlines = [InlineToDoRelation, InlineCanDoRelation]
|
|
autocomplete_fields = ("club",)
|
|
|
|
|
|
class AccidentAdmin(admin.ModelAdmin):
|
|
model = Accident
|
|
|
|
fields = ("date", "gymnast", "educative", "information")
|
|
list_display = ("date", "gymnast", "educative")
|
|
list_filter = ("date",)
|
|
search_fields = ("date", "gymnast", "educative")
|
|
autocomplete_fields = ["gymnast", "educative"]
|
|
|
|
|
|
admin.site.register(Gymnast, GymnastAdmin)
|
|
admin.site.register(Accident, AccidentAdmin)
|
|
admin.site.register(CanDoRelation, CanDoRelationAdmin)
|
|
admin.site.register(ToDoRelation, ToDoRelationAdmin)
|
|
admin.site.register(GymnastHasRoutine, GymnastHasRoutineAdmin)
|