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 %}
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 }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.