django-forms-builder help

49 views
Skip to first unread message

Chris Meek

unread,
Oct 27, 2014, 1:16:41 PM10/27/14
to django...@googlegroups.com
I have an app that uses django-forms-builder. I have got it to display the completed forms without the labels. How do I get it to match the labels next to the fields within my template.

urls.py

url(r'^forms/get/(?P<form_entry_id>\d+)/$', 'gws.views.form', name='form'),
views.py

def
form(request, form_entry_id=1): entry = FormEntry.objects.get(id=form_entry_id) field_entries = FieldEntry.objects.filter(entry=entry) published = Form.objects.published() return render_to_response('form/form.html', {'forms': FormEntry.objects.get(id=form_entry_id), 'form': field_entries })

form.html

<table>
    {% for f in form %}
        <tr>
            <td>{{f.value}}</td>
        </tr>
    {% endfor %}
</table>

Stephen McDonald

unread,
Oct 27, 2014, 3:54:12 PM10/27/14
to django...@googlegroups.com
Each Form and FieldEntry instance has corresponding Field instances - those are where the labels are stored. Each Field instances has a Form ID, and each FieldEntry instance has a Field ID.

Your final code might end up pulling out all the Field instances in the view, passing them to the template (perhaps has a dict mapping Field IDs to labels), and a template tag that takes a FieldEntry instances, looks at its Field ID and returns the label.

Diving into models.py will describe all the above.
Reply all
Reply to author
Forward
0 new messages