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)
+6 -1
View File
@@ -89,7 +89,7 @@ class Testing(models.Model):
class TestAttempt(models.Model):
"""a separate attempt by a user to pass a test"""
testing = models.ForeignKey(Testing, on_delete=models.CASCADE)
testing = models.ForeignKey(Testing, verbose_name='Тест', on_delete=models.CASCADE)
score = models.FloatField(verbose_name='Результат', default=0.0)
attempt_number = models.IntegerField(verbose_name='Номер попытки', default=1)
completion_date = models.DateTimeField(default=datetime.datetime.now,
@@ -99,6 +99,11 @@ class TestAttempt(models.Model):
verbose_name = 'Попытка прохождения теста'
verbose_name_plural = 'Попытки прохождения тестов'
def __str__(self):
employee = DictEmployee.objects.filter(user=self.testing.user).first()
employee = employee.fio if employee else self.testing.user.username
return f"Попытка №{self.attempt_number} теста '{self.testing.test.name}' пользователя {employee}"
class TestResult(models.Model):
"""the result for a specific answer within an attempt"""
attempt = models.ForeignKey(TestAttempt, on_delete=models.CASCADE, related_name='test_results')