Learn how to select specific fields of a model for a serializer to render by exploring Django REST Framework serializers and the configuration options that are available for them.
- In the product serializer, … we already have selected some fields … for rendering through the serializer. … However, we can do a little bit of refactoring … to simplify how we added custom field data. … We can take the attributes that we set … in the two representation method … and refactor them using serializer fields. … We have a boolean field for is on sale. … It is a read-only field. … And for the current price, we have a float field … which is also read-only. … We can now delete two representation and add the fields … to metafields so that they appear in the serializer. … The read-only serializer field configuration parameter … sets whether or not we can write to the field … through the serializer. … Another example of a serializer field configuration … is the source keyword argument. … This can be used if you want to rename a field. … For instance, if you want the rest API to return a field … called 'product name' rather than just 'name'. … Back to the code, we can add a description field …
- 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.