Learn to include custom data in your API, which can help you build code that covers edge cases and nontypical uses of your API. Use ListField and DictField to render a list of models by index and by custom dictionary key. Using JSONField to deserialize and accept custom JSON data through the API.
- [Instructor] In order to gather daily, weekly, … or monthly product and shopping cart data … for our sales report, … we need to create a new serializer … that uses composite fields. … We start by creating the new serializer. … It is not a model serializer. … It's just a plain serializer, … because it's not tied to any specific model. … So, it only contains one field. … It's a DictField, which has … the child parameter set to a ListField, … which has its own child parameter … set to an IntegerField. … So, this is a composite of a composite field. … The dictionary keys will be the date as a string. … For each value in the dictionary, … we're expecting a list of numbers … which is the quantity from each shopping cart … that the product appeared in. … Next, we create a generic API view. … We import GenericAPIView. … We import the rest_framework_response object. … And then, we also import our ProductStatSerializer. … Now we can create our stat API view, ProductStats … The lookup field is the product id. …
- 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.