[Answer]-Two model forms one view form validation not displaying

0๐Ÿ‘

โœ…

You need to include field errors when you manually render the form in the template.

<div class="span1">
    {{ wo_form.subject.errors }}

    <label for="wo_form.complete.label" class="checkbox">
    <input type="checkbox"> {{ wo_form.complete.label }}
    </label>
</div>

For more information, see the docs on customizing the form template. Since you are using bootstrap, you may find crispy forms useful. It makes it easy to render forms that look good with bootstrap.

๐Ÿ‘คAlasdair

1๐Ÿ‘

Form creation:

wo_form = WorkOrderForm(prefix="wo")
store_form = StoreForm(prefix="store")

In template use one tag to post two forms in one time, and then in view:

if request.method == 'POST':
    store_form = StoreForm(request.POST, prefix="store")
    wo_form = WorkOrderForm(request.POST, prefix="wo")
    if 'store_form' in request.POST:            
        if store_form.is_valid():
           store_form.save()
    elif wo_form.is_valid():
           wo_form.save()
....
๐Ÿ‘คdswistowski

Leave a comment