What i want to do is basically user can like an article once. But this error keeps me from liking another article. Here is my code:
class LikePostModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
author = models.ForeignKey(User, unique=True, on_delete=models.CASCADE,related_name='postlikes',null=True)
article = models.ForeignKey(Article, on_delete=models.CASCADE,related_name='postlikes_set')
created = models.DateTimeField(auto_now_add=True)
And here is my error:
Like post model with this Author already exists
How can i solve this problem?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…