Django 联合唯一UniqueConstraint

from django.db import models


class UserAttention(models.Model):
    watcher = models.ForeignKey('user.User', on_delete=models.CASCADE, related_name="attention")
    goal = models.ForeignKey('goal.Goal', on_delete=models.CASCADE, related_name="watcher")
    level = models.IntegerField(verbose_name="亲密度", default=0)

    class Meta:
        constraints = [models.UniqueConstraint(fields=['watcher', 'goal'], name='unique_attention')]

  

用来限制watcher和goal联合唯一索引

 

posted @ 2019-12-02 15:58  很大的龙  阅读(1988)  评论(0编辑  收藏  举报