Learn how to create a serializer that accepts date time fields of specific formats when creating models. This enables you to set sale start and end times for an ecommerce product, for example. Dates and times for calendar events are another example of something that can be enabled through this serializer.
- [Narrator] Now we want to be able to set the sales dates … for our product through the REST API. … We are going to use the DateTime field … to set the start and end dates of a sale. … A Date/Time field can be configured with its input format, … the output format, the help text, and style. … Let's override the sales start and sale end fields … in the Product Serializer. … So the sale start … is a DateTimeField, … and we're setting the input formats. … I'm setting the format to None, … and we will allow null, it's not a required field, … and we are also setting up the help text … with the accepted format, … and the style that will render this field … with a nice placeholder … and then we'd do the same … for the sale end field. … The output format is set to none, … so that the sale start date and end date … are always DateTime objects. … The input formats list can contain any custom format … that is accepted by Python's … string to time conversion function. … The default is iso-8601, …
- 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.