I have uploaded a file earlier.
when I want to change that using new file, the new file is not getting saved.
please, help.
Here the code in view.py
def profile2(request):
# if this is a POST request we need to process the form data
# create a class instance and populate it with data from the request:
if request.method == 'POST' and 'id_document' in request.FILES:
form = ProfileForm(request.POST,request.FILES)
if form.is_valid():
cd = form.cleaned_data
pf = profile(
uname = request.user,
first_name = cd['first_name'],
last_name = cd['last_name'],
birth_date = cd['birth_date'],
Country = cd['Country'],
eMail= cd['eMail'],
id_document = cd['id_document'],
)
pf.registration = False
pf.save()
return HttpResponseRedirect(reverse('index'))
Here is forms.py
class ProfileForm(ModelForm):
class Meta:
model = profile
fields = ['first_name', 'last_name', 'birth_date', 'Country', 'eMail','id_document']
widgets = {
'birth_date': DateInput(attrs={'type': 'date'})
}