register the events stuff into the admin site

A simple admin interface which may be modified later
This commit is contained in:
Martin Pépin 2017-03-18 20:48:45 +00:00
parent c217b549bd
commit 745e7a1c0c
2 changed files with 40 additions and 46 deletions

View file

@ -9,9 +9,7 @@ from .petits_cours_models import PetitCoursDemande, \
PetitCoursSubject, PetitCoursAbility, PetitCoursAttribution, \ PetitCoursSubject, PetitCoursAbility, PetitCoursAttribution, \
PetitCoursAttributionCounter PetitCoursAttributionCounter
from .models import ( from .models import (
SurveyQuestionAnswer, SurveyQuestion, CofProfile, EventOption, SurveyQuestionAnswer, SurveyQuestion, CofProfile, Survey
EventOptionChoice, Event, EventCommentField, EventRegistration,
Survey
) )
@ -62,43 +60,6 @@ class SurveyAdmin(admin.ModelAdmin):
] ]
class EventOptionChoiceInline(admin.TabularInline):
model = EventOptionChoice
@add_link_field(desc_text=lambda x: "Choix",
link_text=lambda x: "Éditer les choix")
class EventOptionInline(admin.TabularInline):
model = EventOption
class EventCommentFieldInline(admin.TabularInline):
model = EventCommentField
class EventOptionAdmin(admin.ModelAdmin):
search_fields = ('event__title', 'name')
inlines = [
EventOptionChoiceInline,
]
class EventAdmin(admin.ModelAdmin):
search_fields = ('title', 'location', 'description')
inlines = [
EventOptionInline,
EventCommentFieldInline,
]
class EventRegistrationAdmin(admin.ModelAdmin):
list_display = ('__unicode__' if six.PY2 else '__str__', 'event', 'user',
'paid')
list_filter = ('paid',)
search_fields = ('user__username', 'user__first_name', 'user__last_name',
'user__email', 'event__title')
class PetitCoursAbilityAdmin(admin.ModelAdmin): class PetitCoursAbilityAdmin(admin.ModelAdmin):
list_display = ('user', 'matiere', 'niveau', 'agrege') list_display = ('user', 'matiere', 'niveau', 'agrege')
search_fields = ('user__username', 'user__first_name', 'user__last_name', search_fields = ('user__username', 'user__first_name', 'user__last_name',
@ -133,8 +94,6 @@ class PetitCoursDemandeAdmin(admin.ModelAdmin):
admin.site.register(Survey, SurveyAdmin) admin.site.register(Survey, SurveyAdmin)
admin.site.register(SurveyQuestion, SurveyQuestionAdmin) admin.site.register(SurveyQuestion, SurveyQuestionAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(EventOption, EventOptionAdmin)
admin.site.register(CofProfile) admin.site.register(CofProfile)
admin.site.register(PetitCoursSubject) admin.site.register(PetitCoursSubject)
admin.site.register(PetitCoursAbility, PetitCoursAbilityAdmin) admin.site.register(PetitCoursAbility, PetitCoursAbilityAdmin)
@ -142,4 +101,3 @@ admin.site.register(PetitCoursAttribution, PetitCoursAttributionAdmin)
admin.site.register(PetitCoursAttributionCounter, admin.site.register(PetitCoursAttributionCounter,
PetitCoursAttributionCounterAdmin) PetitCoursAttributionCounterAdmin)
admin.site.register(PetitCoursDemande, PetitCoursDemandeAdmin) admin.site.register(PetitCoursDemande, PetitCoursDemandeAdmin)
admin.site.register(EventRegistration, EventRegistrationAdmin)

View file

@ -2,7 +2,10 @@ from django.contrib import admin
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User from django.contrib.auth.models import User
from .models import Profile, Club from .models import (
Profile, Club, Event,
EventOption, EventCommentField, EventOptionChoice
)
# --- # ---
@ -19,6 +22,9 @@ class UserProfileAdmin(UserAdmin):
ProfileInline, ProfileInline,
] ]
admin.site.unregister(User)
admin.site.register(User, UserProfileAdmin)
# --- # ---
# Clubs # Clubs
@ -29,5 +35,35 @@ class ClubAdmin(admin.ModelAdmin):
pass pass
admin.site.unregister(User) # ---
admin.site.register(User, UserProfileAdmin) # Events
# ---
class EventOptionChoiceInline(admin.TabularInline):
model = EventOptionChoice
class EventOptionInline(admin.TabularInline):
model = EventOption
show_change_link = True
class EventCommentFieldInline(admin.TabularInline):
model = EventCommentField
@admin.register(EventOption)
class EventOptionAdmin(admin.ModelAdmin):
search_fields = ('event__title', 'name')
inlines = [
EventOptionChoiceInline,
]
@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
search_fields = ['title', 'location', 'description']
inlines = [
EventOptionInline,
EventCommentFieldInline,
]