fix:安部门和分数进行排序
This commit is contained in:
parent
dfd87708da
commit
9222e2ecdf
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.12 on 2024-05-17 07:45
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('system', '0023_alter_user_first_name'),
|
||||
('exam', '0007_auto_20240514_1439'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='examrecord',
|
||||
name='belong_dept',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='examrecord_belong_dept', to='system.organization', verbose_name='所属部门'),
|
||||
),
|
||||
]
|
|
@ -1,5 +1,5 @@
|
|||
from django.db import models
|
||||
from apps.system.models import CommonAModel
|
||||
from apps.system.models import CommonAModel, CommonBModel
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from utils.model import BaseModel
|
||||
from apps.edu.models import Course
|
||||
|
@ -98,7 +98,7 @@ class Exam(CommonAModel):
|
|||
return self.name
|
||||
|
||||
|
||||
class ExamRecord(CommonAModel):
|
||||
class ExamRecord(CommonBModel):
|
||||
'''
|
||||
考试记录表
|
||||
'''
|
||||
|
|
|
@ -91,7 +91,7 @@ class ExamListSerializer(ModelSerializer):
|
|||
class Meta:
|
||||
model = Exam
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
#参与考试的 数量
|
||||
def get_user_count(self, obj):
|
||||
total_user_count = 0
|
||||
|
@ -128,7 +128,10 @@ class ExamRecordListSerializer(serializers.ModelSerializer):
|
|||
took_format = serializers.SerializerMethodField()
|
||||
create_by_name = serializers.CharField(
|
||||
source='create_by.name', read_only=True)
|
||||
|
||||
exam_name = serializers.CharField(
|
||||
source='exam.name', read_only=True)
|
||||
blong_dept_name = serializers.CharField(
|
||||
source='belong_dept.name', read_only=True)
|
||||
class Meta:
|
||||
model = ExamRecord
|
||||
exclude = ('detail',)
|
||||
|
|
|
@ -349,11 +349,13 @@ class ExamRecordViewSet(ListModelMixin, DestroyModelMixin, RetrieveModelMixin, G
|
|||
perms_map = {'get': '*', 'post': '*', 'delete':'examrecord'}
|
||||
queryset = ExamRecord.objects.select_related('create_by')
|
||||
serializer_class = ExamRecordListSerializer
|
||||
ordering_fields = ['create_time', 'score', 'took', 'update_time']
|
||||
ordering_fields = ['create_time', 'score', 'took', 'update_time', 'belong_dept']
|
||||
ordering = ['-update_time']
|
||||
search_fields = ('create_by__name', 'create_by__username')
|
||||
search_fields = ('create_by__name', 'create_by__username', 'exam__name', 'belong_dept__name')
|
||||
filterset_class = ExamRecordFilter
|
||||
|
||||
# 排序
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action == 'retrieve':
|
||||
return ExamRecordDetailSerializer
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.12 on 2024-05-17 07:45
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('information', '0040_alter_qualification_change_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='qualification',
|
||||
name='change_date',
|
||||
field=models.DateField(blank=True, default=datetime.datetime(2024, 5, 17, 7, 45, 18, 898106, tzinfo=utc), null=True, verbose_name='变更日期'),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue