November 2015
Beginner to intermediate
840 pages
26h 30m
English
In the previous section, we determined that our NewsLink objects must be unique according to their slug and startup fields. However, we are not currently enforcing uniqueness in Django or the database.
Luckily, Django makes it easy to enforce uniqueness according to multiple fields, thanks to the unique_together attribute of the nested Meta class, as shown in Example 10.36.
Example 10.36: Project Code
organizer/models.py in ead1b3cad1
70 class NewsLink(models.Model): . ... 77 class Meta: . ... 81 unique_together = (('slug', 'startup'),)
For convenience, instead of passing a tuple of tuples, Django allows us to pass a single tuple if ...
Read now
Unlock full access