feat(problem): 标签名去空格并加大小写不敏感唯一约束

迁移时先合并已存在的重复标签,题目关系转移到保留的那个。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-05 04:07:53 -06:00
parent 6ab336ee8f
commit f0da3de9c0
2 changed files with 57 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
from django.db import models
from django.db.models.functions import Lower
from account.models import User
from contest.models import Contest
@@ -11,6 +12,13 @@ class ProblemTag(models.Model):
class Meta:
db_table = "problem_tag"
constraints = [
models.UniqueConstraint(Lower("name"), name="problem_tag_name_ci_unique"),
]
def save(self, *args, **kwargs):
self.name = (self.name or "").strip()
super().save(*args, **kwargs)
class Problem(models.Model):