From the course: Building RESTful Web APIs with Django
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Date and time fields with serializers
From the course: Building RESTful Web APIs with Django
Date and time fields with serializers
- [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, but we are using a custom format that accepts the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Serializer with only selected fields2m 21s
-
Serializer that shows model relationships3m 57s
-
(Locked)
Number fields with serializers2m 59s
-
(Locked)
Date and time fields with serializers3m 4s
-
(Locked)
Lists, dicts, and JSON objects4m 18s
-
(Locked)
Serializer with ImageField and FileField3m 3s
-
(Locked)
-
-