def additional_info(request, template='main/account/profile.html'): # if this is a POST request we need to process the form data #featured = request.FILES.get('driver-featured_image', None) #inst = request.user.driver if hasattr(request.user, 'driver') else None instance = request.user.driver if hasattr(request.user,'driver') else None if request.method == 'POST': # create a form instance and populate it with data from the request: driverform = DriverForm(request.POST, request.FILES, prefix='driver', instance=instance) # check whether it's valid: if driverform.is_valid(): # process the data in form.cleaned_data as required # ... # redirect to a new URL: #data = driverform.cleaned_data #featured = data.get('featured_image') driver = driverform.save(commit=False) driver.user = request.user driver.save() messages.info(request, _("Your details has been saved!")) return redirect('profile') # if a GET (or any other method) we'll create a blank form else: driverform = DriverForm(prefix='driver', instance=instance) return render(request, template, {'driverform': driverform})
def upd_pic(request, template='main/account/profile.html'): form = DriverForm(data=request.POST, files=request.FILES, instance=request.user.driver) #userform = ProfileForm(prefix='user', instance=request.user) if form.is_valid(): uploaded_file = form.save(commit=False) uploaded_file.featured_image=request.FILES.get('file') uploaded_file.save() #import pdb; pdb.set_trace() data = { 'path': uploaded_file.featured_image.url, } return HttpResponse(json.dumps(data)) return HttpResponseBadRequest(json.dumps({'errors': form.errors}))