Answers for "django unique_together"

1

django unique_together

# Preferred alternative to unique_together, Django 2.2+
# Use the 'constraints' var in class Meta 
class Volume(models.Model):
    id = models.AutoField(primary_key=True)
    journal_id = models.ForeignKey(Journals, db_column='jid', null=True, verbose_name="Journal")
    volume_number = models.CharField('Volume Number', max_length=100)
    comments = models.TextField('Comments', max_length=4000, blank=True)

    class Meta:
        constraints = [
            models.UniqueConstraint(fields=['journal_id', 'volume_number'], name='name of constraint')
        ]
Posted by: Guest on August-13-2021
0

unique_together what is used of it in django

unique_together = [['driver', 'restaurant']]
Posted by: Guest on March-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language