1
0
Files
medical-notes/stroma/quiz/admin/option_admin.py
Johan Dahlin 50366b9b9c
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
vault backup: 2025-12-26 02:09:22
2025-12-26 02:09:22 +01:00

31 lines
1.1 KiB
Python

from django.contrib import admin
from django.utils.html import format_html
from quiz.models import Option
@admin.register(Option)
class OptionAdmin(admin.ModelAdmin):
"""Admin interface for Options"""
list_display = ['id', 'question_preview', 'letter', 'text_preview', 'is_correct']
list_filter = ['letter']
search_fields = ['text', 'question__text']
readonly_fields = ['question']
def question_preview(self, obj):
"""Show question preview"""
return obj.question.text[:40] + '...'
question_preview.short_description = 'Question'
def text_preview(self, obj):
"""Show option text preview"""
return obj.text[:50] + '...' if len(obj.text) > 50 else obj.text
text_preview.short_description = 'Option Text'
def is_correct(self, obj):
"""Highlight if this is the correct answer"""
if obj.question.correct_answer and obj.letter in obj.question.correct_answer:
return format_html('<span style="color: green; font-weight: bold;">✓ Correct</span>')
return format_html('<span style="color: #999;">-</span>')
is_correct.short_description = 'Status'