标签:efault cascade 文章 field pdo down foreign 联合 cad
例:
文章点赞
class ArticleUpDown(models.Model):
"""
点赞表
"""
nid = models.AutoField(primary_key=True)
user = models.ForeignKey(to="UserInfo", null=True, on_delete=models.CASCADE)
article = models.ForeignKey(to="Article", null=True, on_delete=models.CASCADE)
is_up = models.BooleanField(default=True)
class Meta:
unique_together = (("article", "user"),)
verbose_name="点赞"
verbose_name_plural=verbose_name
意思为在这个表中,每一行的user、artical字段必须唯一,否则报错。
django中models联合唯一unique_together
标签:efault cascade 文章 field pdo down foreign 联合 cad
原文地址:https://www.cnblogs.com/ttyypjt/p/10672343.html