From the course: Building RESTful Web APIs with Django

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Serializer with ImageField and FileField

Serializer with ImageField and FileField

From the course: Building RESTful Web APIs with Django

Serializer with ImageField and FileField

- [Narrator] Through the REST API we should be able to update existing product images or upload new product photos. So, let's add the photo field. Go to the product serializer. We add the photo field. And we add it to the list of fields... in meta. Recall that serializer fields can be set as read-only. They can also be set as write-only. This means that when we write to the field the data does not get saved to the model. Now let's do something more interesting. We're going to allow the uploading of a warranty file for a product. We use the file field for this, but since the product model does not have a warranty file field in the model itself, we're going to be adding the write-only configuration option. We're going to override... the update method, so that we can make use of the warranty field. If a warranty file is supplied, we're going to add it to the description of the product. We read-in all the lines from…

Contents