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.
120 lines
3.7 KiB
120 lines
3.7 KiB
from django.contrib import admin
|
|
|
|
from access.models import User
|
|
from courses.models import Lesson, Course, CourseTheme, Homework, Exam, Skills, Achievements, SkillJ, CourseMap, \
|
|
AchievementsMap, Diploma, MaterialDirection
|
|
|
|
|
|
class LessonAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'get_title', 'sort', 'theme', 'token', 'on_comment')
|
|
raw_id_fields = ['materials']
|
|
search_fields = ['title', 'sort', 'id', 'token']
|
|
list_filter = ['course', 'on_comment', 'theme']
|
|
|
|
def get_title(self, obj):
|
|
return obj.title[:100]
|
|
|
|
admin.site.register(Lesson, LessonAdmin)
|
|
|
|
|
|
class MaterialDirectionAdmin(admin.ModelAdmin):
|
|
list_display = ('title', 'color',)
|
|
raw_id_fields = ['mentors']
|
|
|
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
|
if db_field.name == "mentors":
|
|
kwargs["queryset"] = User.objects.filter(in_role='S2')
|
|
return super(MaterialDirectionAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
|
|
|
|
admin.site.register(MaterialDirection, MaterialDirectionAdmin)
|
|
|
|
|
|
class CourseAdmin(admin.ModelAdmin):
|
|
list_display = ('title', 'id', 'direction', 'must_build', 'public', )
|
|
list_filter = ('direction', )
|
|
raw_id_fields = ['teachers']
|
|
search_fields = ['title', 'id']
|
|
filter_horizontal = ['recommend', 'keywords']
|
|
|
|
def formfield_for_manytomany(self, db_field, request, **kwargs):
|
|
if db_field.name == "teachers":
|
|
kwargs["queryset"] = User.objects.filter(in_role='T')
|
|
|
|
if db_field.name == "mentors":
|
|
kwargs["queryset"] = User.objects.filter(in_role='S2')
|
|
|
|
return super(CourseAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
|
|
|
|
admin.site.register(Course, CourseAdmin)
|
|
|
|
|
|
class CourseThemeAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'sort', 'title', 'course', '_type', 'price_type', 'on_comment', )
|
|
list_filter = ['course', '_type', 'on_comment']
|
|
search_fields = ['title', 'sort']
|
|
|
|
admin.site.register(CourseTheme, CourseThemeAdmin)
|
|
|
|
|
|
class HomeworkAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'course', 'theme', 'token')
|
|
search_fields = ['id', 'theme', 'course', 'token']
|
|
list_filter = ('course',)
|
|
raw_id_fields = ('theme', 'course', 'materials', )
|
|
|
|
admin.site.register(Homework, HomeworkAdmin)
|
|
|
|
|
|
class ExamAdmin(admin.ModelAdmin):
|
|
list_display = ('course', 'token', )
|
|
raw_id_fields = ['materials']
|
|
search_fields = ['id', 'course__title']
|
|
|
|
admin.site.register(Exam, ExamAdmin)
|
|
|
|
|
|
class SkillsAdmin(admin.ModelAdmin):
|
|
list_display = ('title', 'color', 'mini_icon', 'big_icon')
|
|
search_fields = ['title']
|
|
|
|
admin.site.register(Skills, SkillsAdmin)
|
|
|
|
|
|
class AchievementsAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'title', 'icon', 'image', 'background', 'border',)
|
|
|
|
|
|
admin.site.register(Achievements, AchievementsAdmin)
|
|
|
|
|
|
class SkillJAdmin(admin.ModelAdmin):
|
|
list_display = ('skill', 'lesson', 'size',)
|
|
raw_id_fields = ['lesson']
|
|
list_filter = ['lesson__course']
|
|
|
|
admin.site.register(SkillJ, SkillJAdmin)
|
|
|
|
|
|
class CourseMapAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'course', 'lesson', 'homework', 'exam', 'sort', 'token', )
|
|
raw_id_fields = ['course', 'lesson', 'homework', 'exam']
|
|
list_filter = ('course',)
|
|
search_fields = ['lesson_id']
|
|
|
|
admin.site.register(CourseMap, CourseMapAdmin)
|
|
|
|
|
|
class AchievementsMapAdmin(admin.ModelAdmin):
|
|
list_display = ('id', 'point', 'achiv', 'after', )
|
|
raw_id_fields = ['point']
|
|
|
|
|
|
admin.site.register(AchievementsMap, AchievementsMapAdmin)
|
|
|
|
|
|
class DiplomaAdmin(admin.ModelAdmin):
|
|
list_filter = ('course__title', 'key', )
|
|
search_fields = ['course__title']
|
|
|
|
|
|
admin.site.register(Diploma, DiplomaAdmin)
|
|
|