This commit is contained in:
@@ -1,3 +1,69 @@
|
||||
from django.contrib import admin
|
||||
from unfold.admin import ModelAdmin
|
||||
from .models import Competition, CompetitionEnrollment, ScoreDimension, Project, ProjectFile, Score, Comment
|
||||
|
||||
# Register your models here.
|
||||
class ScoreDimensionInline(admin.TabularInline):
|
||||
model = ScoreDimension
|
||||
extra = 1
|
||||
tab = True
|
||||
|
||||
class ProjectFileInline(admin.TabularInline):
|
||||
model = ProjectFile
|
||||
extra = 0
|
||||
tab = True
|
||||
|
||||
@admin.register(Competition)
|
||||
class CompetitionAdmin(ModelAdmin):
|
||||
list_display = ['title', 'status', 'start_time', 'end_time', 'is_active', 'created_at']
|
||||
list_filter = ['status', 'is_active']
|
||||
search_fields = ['title', 'description']
|
||||
inlines = [ScoreDimensionInline]
|
||||
|
||||
actions = ['make_published', 'make_ended']
|
||||
|
||||
def make_published(self, request, queryset):
|
||||
queryset.update(status='published')
|
||||
make_published.short_description = "发布选中比赛"
|
||||
|
||||
def make_ended(self, request, queryset):
|
||||
queryset.update(status='ended')
|
||||
make_ended.short_description = "结束选中比赛"
|
||||
|
||||
@admin.register(CompetitionEnrollment)
|
||||
class CompetitionEnrollmentAdmin(ModelAdmin):
|
||||
list_display = ['competition', 'user', 'role', 'status', 'created_at']
|
||||
list_filter = ['competition', 'role', 'status']
|
||||
search_fields = ['user__nickname', 'competition__title']
|
||||
actions = ['approve_enrollment', 'reject_enrollment']
|
||||
|
||||
def approve_enrollment(self, request, queryset):
|
||||
queryset.update(status='approved')
|
||||
approve_enrollment.short_description = "通过审核"
|
||||
|
||||
def reject_enrollment(self, request, queryset):
|
||||
queryset.update(status='rejected')
|
||||
reject_enrollment.short_description = "拒绝申请"
|
||||
|
||||
@admin.register(Project)
|
||||
class ProjectAdmin(ModelAdmin):
|
||||
list_display = ['title', 'competition', 'contestant', 'status', 'final_score', 'created_at']
|
||||
list_filter = ['competition', 'status']
|
||||
search_fields = ['title', 'contestant__user__nickname']
|
||||
inlines = [ProjectFileInline]
|
||||
readonly_fields = ['final_score']
|
||||
|
||||
@admin.register(Score)
|
||||
class ScoreAdmin(ModelAdmin):
|
||||
list_display = ['project', 'judge', 'dimension', 'score', 'created_at']
|
||||
list_filter = ['project__competition', 'dimension']
|
||||
search_fields = ['project__title', 'judge__user__nickname']
|
||||
|
||||
@admin.register(Comment)
|
||||
class CommentAdmin(ModelAdmin):
|
||||
list_display = ['project', 'judge', 'content_preview', 'created_at']
|
||||
list_filter = ['project__competition']
|
||||
search_fields = ['project__title', 'judge__user__nickname', 'content']
|
||||
|
||||
def content_preview(self, obj):
|
||||
return obj.content[:50] + '...' if len(obj.content) > 50 else obj.content
|
||||
content_preview.short_description = "评语内容"
|
||||
|
||||
Reference in New Issue
Block a user