Learn how to create a new model instance using the CreateAPIView. This video covers query parameters, the CreateAPIView subclass, and model fields populated from query parameters.
- [Instructor] Now we want the ability … to create new products through the API. … In the API views we will create … the product creation API view. … From REST framework we're going to import … the exceptions that we need, … and import the create API view. … The bottom of the file we're going to create … our new product creation, API view. … Reusing our serialiser class. … And then overwriting the creating method. … We're going to extract the price from the parameters. … We're going to ensure that the price is set … And that the price is above $0, … so that it is not free. … If either of these conditions fail, … we just raise a validation error on the price field, … saying must be above $0. … We also ... … cache the value error exception … just in case parsing the price doesn't work. … And then we'll erase another validation error, … and we say that the price … needs to be a number. … After that we just call super and create. … The validation of the price is to prevent anyone … using the REST API from accidentally …
- Creating a serializer
- Working with API views
- Filtering back ends
- Enabling pagination
- Executing CRUD operations
- Managing serializer fields
- Testing API views
Skill Level Intermediate
Deploying Django Apps: Make Your Site Go Livewith Nick Walter2h 43m Intermediate
Demo project overview1m 19s
1. Serializing, Listing, Filtering, and Paginating Models
2. Create, Retrieve, Update, and Delete (CRUD) Operations for Models
3. Managing Serializer Fields, Relations, and Validation
4. Testing API Views
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.