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