62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
from django.contrib import admin
|
|
from django.utils.translation import gettext_lazy as _
|
|
from .models import Course, Chapter, ChapterContent, CourseFavorite, CourseMaterial
|
|
|
|
|
|
class ChapterInline(admin.StackedInline):
|
|
model = Chapter
|
|
extra = 0
|
|
|
|
|
|
class ChapterContentInline(admin.StackedInline):
|
|
model = ChapterContent
|
|
extra = 0
|
|
|
|
|
|
class MaterialInline(admin.TabularInline):
|
|
model = CourseMaterial
|
|
extra = 0
|
|
|
|
|
|
@admin.register(Course)
|
|
class CourseAdmin(admin.ModelAdmin):
|
|
list_display = ['title', 'category', 'level', 'status', 'author', 'sort_order', 'is_hot', 'is_new', 'created_at']
|
|
list_filter = ['category', 'level', 'status', 'is_hot', 'is_new']
|
|
search_fields = ['title', 'description']
|
|
ordering = ['-sort_order', '-created_at']
|
|
inlines = [ChapterInline]
|
|
|
|
|
|
@admin.register(Chapter)
|
|
class ChapterAdmin(admin.ModelAdmin):
|
|
list_display = ['title', 'course', 'sort_order', 'duration', 'is_free', 'created_at']
|
|
list_filter = ['course', 'is_free']
|
|
search_fields = ['title']
|
|
ordering = ['sort_order']
|
|
inlines = [ChapterContentInline, MaterialInline]
|
|
|
|
|
|
@admin.register(CourseMaterial)
|
|
class CourseMaterialAdmin(admin.ModelAdmin):
|
|
list_display = ['title', 'chapter', 'file_type', 'file_size', 'download_count', 'sort_order', 'created_at']
|
|
list_filter = ['file_type', 'created_at']
|
|
search_fields = ['title', 'chapter__title']
|
|
ordering = ['sort_order']
|
|
readonly_fields = ['download_count', 'created_at']
|
|
|
|
|
|
@admin.register(ChapterContent)
|
|
class ChapterContentAdmin(admin.ModelAdmin):
|
|
list_display = ['chapter', 'md_file_path', 'updated_at']
|
|
search_fields = ['content_md', 'chapter__title']
|
|
|
|
|
|
@admin.register(CourseFavorite)
|
|
class CourseFavoriteAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'course', 'created_at']
|
|
list_filter = ['created_at']
|
|
search_fields = ['user__username', 'course__title']
|
|
ordering = ['-created_at']
|
|
list_per_page = 30
|
|
readonly_fields = ['created_at']
|