I need to save the file through the form, do this:
models.py class Post(models.Model): title = models.CharField(max_length=255) image = ImageField(upload_to='images') forms.py class PostForm(forms.ModelForm): class Meta: model = Post views.py class PostCreateView(CreateView): form_class = PostForm template_name = 'create.html' success_url = '/'
For example, if I selected a file and did not fill in the title, the page reloads, the title says that the field is mandatory, and the selected file is not displayed, I fill the title and do not select the file again, reloads the page and says that the file is not selected, but if re-select the file, it will be saved ...
I'm wondering, is CreateView working incorrectly with files, or am I doing something wrong?