def form_save_and_edit(request, id=None, template_name='create.html'): """ referring data from "model_from_json()", making data visible within another function """ func = model_from_json() """ savind and editing form data in the same form """ form = UserDataForm(request.POST) if request.POST: updated_field = form.save() last_name = request.session['last_name'] = updated_field.last_name first_name = request.session['first_name'] = updated_field.first_name email = request.session['email'] = updated_field.email skype = request.session['skype'] = updated_field.skype form = UserDataForm({ 'last_name': last_name, 'first_name': first_name, 'skype':skype, 'email':email }) redirect_url = reverse('create') message = messages.info(request, "You successfully updated your profile!") if form.is_valid(): form.save() else: form = UserDataForm({ 'last_name': func['last_name'], 'first_name':func['first_name'], 'email':func['email'], 'skype':func['skype'], }) message = messages.success(request, "You just loaded your profile initial data") return render_to_response('create.html', {'form': form,}, context_instance=RequestContext(request))
def form_edit(request, id=None, template_name='create.html'): func = model_from_json() try: id = request.session['id'] new_record = User.objects.get(id=id) form = UserDataForm(request.POST, instance=new_record) except: form = UserDataForm({ 'last_name': func['last_name'], 'first_name': func['first_name'], 'email': func['email'], # 'date':func['date'] }) if form.is_valid(): form.save() try: form = UserDataForm(request.POST) if form.is_valid(): form.save() except Exception, e: print e
def form_edit(request, id=None, template_name='create.html'): func = model_from_json() try: id = request.session['id'] new_record=User.objects.get(id=id) form=UserDataForm(request.POST, instance = new_record) except: form = UserDataForm({ 'last_name': func['last_name'], 'first_name':func['first_name'], 'email':func['email'], # 'date':func['date'] }) if form.is_valid(): form.save() try: form=UserDataForm(request.POST) if form.is_valid(): form.save() except Exception, e: print e