Django: Getting Started Transcripts
Chapter: Posting Data
Lecture: Adding constraints to the 'ReviewModel'

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Database constraints, on the other hand, go in a meta inter class configuration area.
0:06 You've seen this area before to configure things like the default sort order, the name of the model in the admin, and to create database indexes.
0:15 In this case, the constraints attribute of the meta inter class is used to add a database constraint.
0:21 The constraints themselves are found in the models module. Here I'm using the unique constraint constraint.
0:29 It ensures that fields in this constraint are unique when used together. In this specific case, a review must be unique to a user and a book
0:38 Together, users won't be able to submit multiple reviews for the same book. Most constraints require a name field.
0:46 This has to do with the underlying configuration of the database. Alright, that's the model. Let me show you the corresponding admin code.


Talk Python's Mastodon Michael Kennedy's Mastodon