2018-05-21 19:28:36 +02:00
|
|
|
from django.contrib import admin
|
2018-05-22 11:10:09 +02:00
|
|
|
from import_export import resources
|
|
|
|
from import_export.admin import ExportMixin
|
2018-05-21 19:28:36 +02:00
|
|
|
|
2018-05-22 10:13:51 +02:00
|
|
|
from manuels.models import Teacher, Book, Level, Editor, SuppliesRequirement
|
2018-05-21 23:12:35 +02:00
|
|
|
|
|
|
|
|
2018-05-22 11:10:09 +02:00
|
|
|
class TeacherResource(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = Teacher
|
|
|
|
fields = ('first_name', 'last_name', 'email', 'phone_number')
|
|
|
|
|
|
|
|
|
2018-05-21 23:12:35 +02:00
|
|
|
@admin.register(Teacher)
|
2018-05-22 11:10:09 +02:00
|
|
|
class TeacherAdmin(ExportMixin, admin.ModelAdmin):
|
|
|
|
resource_class = TeacherResource
|
2018-05-22 01:43:39 +02:00
|
|
|
list_display = ['full_name', 'email', 'phone_number']
|
2018-05-21 23:12:35 +02:00
|
|
|
|
2018-05-22 11:10:27 +02:00
|
|
|
def send_link(self, request, queryset):
|
2018-05-22 10:24:21 +02:00
|
|
|
for teacher in queryset:
|
|
|
|
teacher.send_link(request)
|
|
|
|
|
|
|
|
send_link.short_description = 'Envoyer le lien'
|
|
|
|
|
|
|
|
actions = [send_link]
|
|
|
|
|
2018-05-21 23:12:35 +02:00
|
|
|
|
|
|
|
@admin.register(Level)
|
|
|
|
class LevelAdmin(admin.ModelAdmin):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2018-05-22 11:10:09 +02:00
|
|
|
class BookResource(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = Book
|
2018-05-24 00:08:09 +02:00
|
|
|
fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn',
|
2018-05-22 11:10:09 +02:00
|
|
|
'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field')
|
2018-05-24 00:31:21 +02:00
|
|
|
export_order = ('field', 'title', 'authors', 'editor__name', 'publication_year', 'isbn', 'price',
|
|
|
|
'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name')
|
2018-05-22 11:10:09 +02:00
|
|
|
|
|
|
|
|
2018-05-21 23:12:35 +02:00
|
|
|
@admin.register(Book)
|
2018-05-22 11:10:09 +02:00
|
|
|
class BookAdmin(ExportMixin, admin.ModelAdmin):
|
|
|
|
resource_class = BookResource
|
2018-05-24 00:31:21 +02:00
|
|
|
list_display = ['level', 'field', 'title', 'authors', 'editor', 'publication_year', 'isbn',
|
2018-05-30 18:06:27 +02:00
|
|
|
'price', 'previously_acquired', 'teacher', 'done']
|
|
|
|
list_filter = ['done', 'editor', 'previously_acquired', 'teacher', 'level']
|
2018-05-24 00:31:21 +02:00
|
|
|
list_display_links = ['title']
|
2018-05-22 01:45:55 +02:00
|
|
|
fieldsets = [
|
|
|
|
('Infos livre', {
|
2018-05-24 00:07:26 +02:00
|
|
|
'fields': ('title', 'authors', 'editor', 'publication_year', 'isbn', 'created_at', 'updated_at')
|
2018-05-22 01:45:55 +02:00
|
|
|
}),
|
|
|
|
('Élève', {
|
|
|
|
'fields': ('price', 'previously_acquired',)
|
|
|
|
}),
|
|
|
|
('Enseignant', {
|
|
|
|
'fields': ('teacher', 'level', 'field')
|
|
|
|
}),
|
2018-05-30 18:06:27 +02:00
|
|
|
('Gestion', {
|
|
|
|
'fields': ('done',)
|
|
|
|
}),
|
2018-05-22 01:45:55 +02:00
|
|
|
]
|
|
|
|
readonly_fields = ['created_at', 'updated_at']
|
2018-05-22 01:35:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Editor)
|
|
|
|
class EditorAdmin(admin.ModelAdmin):
|
|
|
|
pass
|
2018-05-22 10:13:51 +02:00
|
|
|
|
|
|
|
|
2018-05-22 11:10:09 +02:00
|
|
|
class SuppliesResource(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = SuppliesRequirement
|
2018-05-24 00:36:17 +02:00
|
|
|
fields = ('supplies', 'fields', 'level__name', 'teacher__first_name', 'teacher__last_name')
|
|
|
|
export_order = ('fields', 'supplies', 'teacher__first_name', 'teacher__last_name', 'level__name')
|
2018-05-22 11:10:09 +02:00
|
|
|
|
|
|
|
|
2018-05-22 10:13:51 +02:00
|
|
|
@admin.register(SuppliesRequirement)
|
2018-05-22 11:10:09 +02:00
|
|
|
class SuppliesRequirementAdmin(ExportMixin, admin.ModelAdmin):
|
|
|
|
resource_class = SuppliesResource
|
2018-05-30 18:06:27 +02:00
|
|
|
list_display = ['id', 'teacher', 'level', 'fields', 'supplies', 'done']
|
2018-05-22 10:13:51 +02:00
|
|
|
readonly_fields = ['created_at', 'updated_at']
|
2018-05-30 18:06:27 +02:00
|
|
|
list_filter = ['done', 'teacher', 'level']
|