force to delete a problem even when it has submissions.

This commit is contained in:
shaohuihuang 2018-12-11 21:52:22 +08:00
parent a8175af78f
commit fb2015fc8c
2 changed files with 5 additions and 5 deletions

View File

@ -300,8 +300,8 @@ class ProblemAPI(ProblemBase):
except Problem.DoesNotExist:
return self.error("Problem does not exists")
ensure_created_by(problem, request.user)
if Submission.objects.filter(problem=problem).exists():
return self.error("Can't delete the problem as it has submissions")
#if Submission.objects.filter(problem=problem).exists():
# return self.error("Can't delete the problem as it has submissions")
d = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
if os.path.isdir(d):
shutil.rmtree(d, ignore_errors=True)
@ -430,8 +430,8 @@ class ContestProblemAPI(ProblemBase):
except Problem.DoesNotExist:
return self.error("Problem does not exists")
ensure_created_by(problem.contest, request.user)
if Submission.objects.filter(problem=problem).exists():
return self.error("Can't delete the problem as it has submissions")
#if Submission.objects.filter(problem=problem).exists():
# return self.error("Can't delete the problem as it has submissions")
d = os.path.join(settings.TEST_CASE_DIR, problem.test_case_id)
if os.path.isdir(d):
shutil.rmtree(d, ignore_errors=True)

View File

@ -23,7 +23,7 @@ class JudgeStatus:
class Submission(models.Model):
id = models.TextField(default=rand_str, primary_key=True, db_index=True)
contest = models.ForeignKey(Contest, null=True)
problem = models.ForeignKey(Problem)
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)
create_time = models.DateTimeField(auto_now_add=True)
user_id = models.IntegerField(db_index=True)
username = models.TextField()