From 51f9849c32a0a6598e01397d5a91c586c414d799 Mon Sep 17 00:00:00 2001 From: st42597 Date: Wed, 23 Mar 2022 08:53:41 +0000 Subject: [PATCH] fix: foreign key --- backend/temperature/models.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/temperature/models.py b/backend/temperature/models.py index b9f548b2d..887c1e4a4 100644 --- a/backend/temperature/models.py +++ b/backend/temperature/models.py @@ -1,5 +1,6 @@ from django.db import models -from utils.shortcuts import rand_str +from problem.models import Problem +from account.models import User class JudgeStatus: @@ -29,24 +30,23 @@ class ProblemScore: class Temperature(models.Model): - user_id = models.IntegerField(unique=True) + user = models.ForeignKey(User, null=True, on_delete=models.CASCADE) temperature = models.IntegerField(default=0) date = models.DateField(auto_now_add=True) class Meta: db_table = "temperature" - unique_together = (("user_id", "date"),) + unique_together = (("user", "date"),) ordering = ("-date",) class SolvedProblem(models.Model): - id = models.TextField(default=rand_str, primary_key=True, db_index=True) - user_id = models.IntegerField(db_index=True) - _id = models.TextField(db_index=True, default=0) + user = models.ForeignKey(User, null=True, on_delete=models.CASCADE) + problem = models.ForeignKey(Problem, null=True, on_delete=models.CASCADE) score = models.IntegerField() solved_time = models.DateField(auto_now_add=True) class Meta: db_table = "solvedproblem" - unique_together = (("user_id", "_id"),) + unique_together = (("user", "problem"),) ordering = ("-solved_time",)