Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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')
        ]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #django
ADD COMMENT
Topic
Name
5+1 =