manuels-scolaires/manuels/admin.py

89 lines
3 KiB
Python
Raw Normal View History

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
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
list_display = ['full_name', 'email', 'phone_number', 'has_confirmed_list']
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-06-24 17:33:32 +02:00
fields = ('title', 'authors', 'editor__name', 'publication_year', 'isbn', 'comments', 'other_editor',
2019-04-06 19:25:04 +02:00
'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field',
'consumable')
export_order = ('level__name', 'field', 'title', 'authors', 'editor__name', 'publication_year', 'isbn', 'price',
2019-04-06 19:25:04 +02:00
'other_editor', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'comments',
'consumable')
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-06-10 22:15:58 +02:00
list_display = ['level', 'field', 'title', 'authors', 'editor', 'other_editor', 'publication_year', 'isbn',
2018-05-30 18:06:27 +02:00
'price', 'previously_acquired', 'teacher', 'done']
2018-06-02 16:35:52 +02:00
list_editable = ['done']
2018-06-02 16:41:50 +02:00
list_filter = ['done', 'previously_acquired', 'level', 'editor', 'teacher']
list_display_links = ['title']
fieldsets = [
('Infos livre', {
2018-06-10 22:15:58 +02:00
'fields': ('title', 'authors', ('editor', 'other_editor'), 'publication_year',
'isbn', 'created_at', 'updated_at', 'comments')
}),
('Élève', {
'fields': ('price', 'previously_acquired',)
}),
('Coordonnateur', {
'fields': ('teacher', 'level', 'field')
}),
2018-05-30 18:06:27 +02:00
('Gestion', {
'fields': ('done',)
}),
]
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 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 = ('level__name', 'fields', 'supplies', 'teacher__first_name', 'teacher__last_name')
2018-05-22 11:10:09 +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-06-02 16:35:52 +02:00
list_editable = ['done']
readonly_fields = ['created_at', 'updated_at']
2018-05-30 18:06:27 +02:00
list_filter = ['done', 'teacher', 'level']