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聯合唯一索引

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM