You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.0 KiB
33 lines
1.0 KiB
from django.contrib import admin
|
|
|
|
from apps.course.models import Lesson, LessonCompletion
|
|
|
|
|
|
|
|
|
|
@admin.register(Lesson)
|
|
class LessonAdmin(admin.ModelAdmin):
|
|
list_display = ('title', 'course', 'priority', 'duration', 'content_type')
|
|
list_filter = ('course', 'content_type')
|
|
search_fields = ('title', 'course__title')
|
|
ordering = ('priority', 'title')
|
|
|
|
def get_queryset(self, request):
|
|
qs = super().get_queryset(request)
|
|
return qs.order_by('priority')
|
|
|
|
|
|
@admin.register(LessonCompletion)
|
|
class LessonCompletionAdmin(admin.ModelAdmin):
|
|
list_display = ('student', 'lesson', 'completed_at')
|
|
search_fields = ('student__fullname', 'student__email', 'lesson__title', 'lesson__course__title')
|
|
list_filter = ('lesson__course', 'completed_at')
|
|
ordering = ('-completed_at',)
|
|
|
|
def get_readonly_fields(self, request, obj=None):
|
|
"""
|
|
Make fields readonly if the object already exists.
|
|
"""
|
|
if obj:
|
|
return ['student', 'lesson', 'completed_at']
|
|
return []
|