例:
文章点赞
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字段必须唯一,否则报错。
原文地址:https://www.cnblogs.com/ttyypjt/p/10672343.html
时间: 2024-10-16 03:26:36