From the course: Building RESTful Web APIs with Django
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Number fields with serializers
From the course: Building RESTful Web APIs with Django
Number fields with serializers
- [Lecturer] We are now going to use number fields with the product serializer. Let's update the CartItemSerializer first with an IntegerField for the quantity. We're going to ensure that only between one and 100 items of a particular type can be added to the shopping cart. And now for products, we want to ensure that whenever we create or update them through the API, that the minimum price is set to at least $1 and the maximum price is never more than $100,000. We can do this through the FloatField Configuration keyword arguments, min_value and max_value. For example, most e-commerce sites will only allow free items through 100% off coupons and discount codes, such as the Bungie store website for the Destiny game which uses a very large price for products that require a discount code. Now let's implement the FloatField for the product price. We set the min_value to $1 and the max_value to 100,000. The DecimalField is more powerful than the FloatField and actually is in better…
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)
-
-