All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
from django.contrib import admin
|
|
from django.utils.safestring import mark_safe
|
|
from quiz.models import QuizResult
|
|
|
|
|
|
@admin.register(QuizResult)
|
|
class QuizResultAdmin(admin.ModelAdmin):
|
|
"""Admin interface for Quiz Results"""
|
|
list_display = ['id', 'user_preview', 'question_preview', 'selected_answer', 'correct_answer', 'result_status', 'answered_at']
|
|
list_filter = ['is_correct', 'answered_at']
|
|
search_fields = ['user__session_key', 'question__text']
|
|
readonly_fields = ['user', 'question', 'selected_answer', 'is_correct', 'answered_at']
|
|
|
|
def user_preview(self, obj):
|
|
"""Show user session preview"""
|
|
return f"{obj.user.session_key[:8]}..."
|
|
user_preview.short_description = 'User'
|
|
|
|
def question_preview(self, obj):
|
|
"""Show question preview"""
|
|
return obj.question.text[:40] + '...'
|
|
question_preview.short_description = 'Question'
|
|
|
|
def correct_answer(self, obj):
|
|
"""Show correct answer"""
|
|
return obj.question.correct_answer
|
|
correct_answer.short_description = 'Correct'
|
|
|
|
def result_status(self, obj):
|
|
"""Show visual result status"""
|
|
if obj.is_correct:
|
|
return mark_safe('<span style="color: green; font-weight: bold;">✓ Correct</span>')
|
|
return mark_safe('<span style="color: red; font-weight: bold;">✗ Wrong</span>')
|
|
result_status.short_description = 'Result'
|
|
|