P-259: admin test result

This commit is contained in:
cja committed 2025-06-03 14:50:53 +03:00
1 parent fdb1deb97f
commit 7d8c612799
2 files changed
+28 -2

No files matched your search

+22 -1
View File
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Test, TestAnswer, TestQuestion
from .models import Test, TestAnswer, TestQuestion, TestAttempt, DictEmployee
import nested_admin
class TestAnswerInline(nested_admin.NestedStackedInline):
@@ -14,4 +14,25 @@ class TestQuestionInline(nested_admin.NestedStackedInline):
class TestAdmin(nested_admin.NestedModelAdmin):
inlines = [TestQuestionInline]
@admin.register(TestAttempt)
class TestAttemptAdmin(admin.ModelAdmin):
# list_display = ('testing_user', 'testing_test', 'score', 'completion_date')
list_display = ('get_user_fio', 'testing_test', 'score', 'completion_date')
def get_user_fio(self, obj):
employee = DictEmployee.objects.filter(user=obj.testing.user).first()
return employee.fio if employee else obj.testing.user.username
# def testing_user(self, obj):
# return obj.testing.user.username
# testing_user.short_description = 'Пользователь'
# testing_user.admin_order_field = 'testing__user'
def testing_test(self, obj):
return obj.testing.test
get_user_fio.short_description = 'Пользователь'
testing_test.short_description = 'Тест'
testing_test.admin_order_field = 'testing__test'
admin.site.register(Test, TestAdmin)