django-constraints

Unique together between field and model connected by ForeignKey django

Unique together between field and model connected by ForeignKey django Question: I have two models. class Post(models.Model): title = models.CharField(max_length=150) class Attachment(models.Model): type = models.CharField(choices=AttachmentChoices.get_choices(), max_length=15) link = models.URLField() post = models.ForeignKey(‘Post’, on_delete=models.PROTECT, related_name=’attachments’) I want to do something like this in meta class of Post model class Meta: unique_together = [(‘title’, ‘attachments’)] but it …

Total answers: 1