4

I am using django-forms-builder in my project and there is just one thing i cant get my head around. How do i set up an update form to edit a filled out form?

Here is my attempt at making an update form for django-forms-builder

urls.py

url('forms/update/(?P<pk>\d+)/$', FormUpdateView.as_view(), name='form-update'), 

views.py

class FormUpdateView(UpdateView): model = FieldEntry template_name = 'form/update_form.html' form_class = FormForForm success_url = '/assessments/all/' 

update-form.py

{% render_built_form id=form_instance.id %} 
2
  • you need to find a way to pass an instance of the form model into your view as form_instance Commented Oct 28, 2014 at 19:02
  • you're probably best sub-classing or modifying the existing FormDetail view that comes with django-forms-builder github.com/stephenmcd/django-forms-builder/blob/master/… Commented Oct 28, 2014 at 19:05

1 Answer 1

4
+50

I haven't used this software yet but it could fill a spot in my arsenal so I took a stab at it. I'm not using CBV because I'm still just poking around. This is the get part only, I can expand on how to handle the post part (and preferably do it with CBV) on the weekend. It's relatively straightforward to implement post with view functions (if request.METHOD == "POST":#update the row). The render is of course just plain raw HTML but forms_builder doesn't offer any styling input. You probably want to tack the user onto the FormEntry, I don't have a good idea about authorization yet. I'll give it some thought and amend the answer.

views.py

from forms_builder.forms.models import Form def get_form(request, slug, pk): form_obj = Form.objects.get(slug=slug) form_instance = form_obj.entries.get(pk=pk) form = FormForForm(form=form_obj, instance=form_instance, context=request) return render_to_response('update_form.html', {'form':form_instance.form, 'request':request}) 

templates/update_form.html

{{ form.as_p }} 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.