2👍
Why do you want to handle file attachments by yourself, django will do it for you.
Properties of FileField is here. I uesd it a few times before, i can not remember exactly butusing something as following must do the job…
First, create your form from related model:
class SomeFormWithFileForm(forms.ModelForm):
class Meta:
model = SomeModel
then in your view, where you create your form instance,
form = SomeFormWithFileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
will do the trick.
Source:stackexchange.com