From c0696859be6e309ffc1bb3860b99c962c26efd4d Mon Sep 17 00:00:00 2001 From: CapooL <2053217188@qq.com> Date: Wed, 6 Dec 2023 23:21:47 +0800 Subject: [PATCH] refactor(words): rename variable --- .../quiz/migrations/0005_paper_record.py | 3 +-- hinghwa-dict-backend/quiz/models.py | 2 +- .../quiz/paper/dto/paper_record_dto.py | 2 +- .../quiz/paper/view/paper_record_all.py | 10 +++++----- .../quiz/paper/view/paper_record_single.py | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hinghwa-dict-backend/quiz/migrations/0005_paper_record.py b/hinghwa-dict-backend/quiz/migrations/0005_paper_record.py index 75260d92..bef876cb 100644 --- a/hinghwa-dict-backend/quiz/migrations/0005_paper_record.py +++ b/hinghwa-dict-backend/quiz/migrations/0005_paper_record.py @@ -24,7 +24,7 @@ class Migration(migrations.Migration): ), ), ( - "examine", + "contributor", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name="paper_user", @@ -35,7 +35,6 @@ class Migration(migrations.Migration): ( "paper", models.ForeignKey( - blank=True, on_delete=django.db.models.deletion.CASCADE, related_name="papers", to="quiz.paper", diff --git a/hinghwa-dict-backend/quiz/models.py b/hinghwa-dict-backend/quiz/models.py index 55a570a9..e4d3bd96 100644 --- a/hinghwa-dict-backend/quiz/models.py +++ b/hinghwa-dict-backend/quiz/models.py @@ -49,7 +49,7 @@ class Paper(models.Model): class PaperRecord(models.Model): - examine = models.ForeignKey( + contributor = models.ForeignKey( User, on_delete=models.CASCADE, related_name="paper_user", verbose_name="答卷人" ) timestamp = models.DateTimeField(verbose_name="时间") diff --git a/hinghwa-dict-backend/quiz/paper/dto/paper_record_dto.py b/hinghwa-dict-backend/quiz/paper/dto/paper_record_dto.py index 5e1e8c2d..fd39d34a 100644 --- a/hinghwa-dict-backend/quiz/paper/dto/paper_record_dto.py +++ b/hinghwa-dict-backend/quiz/paper/dto/paper_record_dto.py @@ -7,7 +7,7 @@ def paper_record_all(paper_record: PaperRecord): response = { "id": paper_record.id, - "user": user_simple(paper_record.examine), + "user": user_simple(paper_record.contributor), "timestamp": paper_record.timestamp, "paper": paper_all(paper_record.paper), } diff --git a/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py b/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py index 1c845b51..e7b92232 100644 --- a/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py +++ b/hinghwa-dict-backend/quiz/paper/view/paper_record_all.py @@ -18,25 +18,25 @@ class PaperRecordAll(View): @csrf_exempt def post(self, request): token_pass(request.headers, -1) - examine = request.GET["examine"] + contributor = request.GET["contributor"] paper = request.GET["paper"] - user = User.objects.filter(id=examine) + user = User.objects.filter(id=contributor) paper = Paper.objects.filter(id=paper) user = user[0] paper = paper[0] record = PaperRecord() record.timestamp = timezone.now() record.id = generate_paper_record_id() - record.examine = user + record.contributor = user record.paper = paper record.save() return JsonResponse(paper_record_all(record)) - # QZ0302 查询对应用户答题记录 + # QZ0302 查询对应用户答卷记录 def get(self, request): user_id = request.GET["user_id"] token_pass(request.headers, int(user_id)) - total_records = PaperRecord.objects.filter(examine=get_user_by_id(user_id)) + total_records = PaperRecord.objects.filter(contributor=get_user_by_id(user_id)) results = [] for record in total_records: results.append(paper_record_all(record)) diff --git a/hinghwa-dict-backend/quiz/paper/view/paper_record_single.py b/hinghwa-dict-backend/quiz/paper/view/paper_record_single.py index 25a6f448..107393a7 100644 --- a/hinghwa-dict-backend/quiz/paper/view/paper_record_single.py +++ b/hinghwa-dict-backend/quiz/paper/view/paper_record_single.py @@ -13,6 +13,6 @@ def get(self, request, record_id): if not record.exists(): raise PaperRecordNotFoundException() record = record[0] - user_id = record.examine.id + user_id = record.contributor.id token_pass(request.headers, user_id) return JsonResponse(paper_record_all(record), status=200)