May 2018
Beginner to intermediate
526 pages
11h 57m
English
As you know, ModelForm provides a save() method to save the current model instance to the database and return the object. This method receives a boolean commit parameter, which allows you to specify whether the object has to be persisted to the database. If commit is False, the save() method will return a model instance but will not save it to the database. We will override the save() method of our form in order to retrieve the given image and save it.
Add the following imports at the top of the forms.py file:
from urllib import requestfrom django.core.files.base import ContentFilefrom django.utils.text import slugify
Then, add the following save() method to the ImageCreateForm form:
def save(self, ...
Read now
Unlock full access