Django - Form FileField error "This field is required"

Viewed 7444

I want to add Post form into my django project and I've got problem with FileFiled. Here is my code:

forms.py

class PostForm(forms.ModelForm):

   class Meta:
      model = Post
      fields = [
        'author',
        'image',
        'title',
        'body'
    ]

models.py

class Post(models.Model):
    author = models.ForeignKey('auth.User')
    image = models.FileField(default="", blank=False, null=False)
    title = models.CharField(max_length=200)
    body = models.TextField()
    date = models.DateTimeField(default=timezone.now, null=True)

    def approved_comments(self):
        return self.comments.filter(approved_comment=True)

    def __str__(self):
        return self.title

If it helps. I also set enctype="multipart/form-data in <form>

Thanks for help.

2 Answers
Related