0
I have model, form and template for units, and in this same template I need to add a region form (these are exams). How can I add this form in the view so it can be edited in the drive template?
py views.
class CreateUnitView(CreateView):
form_class = UnitForm
template_name = 'units/unit_form.html'
success_url = 'list' 
def get_context_data(self, **kwargs):
    pdb.set_trace()
    context = super(CreateUnitView, self).get_context_data(**kwargs)
    if self.request.POST:
        pdb.set_trace()
        context['forms'] = UnitForm(self.request.POST)
    else:
        context['forms'] = UnitForm()
    return context
def form_valid(self, form):
    context = self.get_context_data()
    forms = context['forms']
    if forms.is_valid(): 
        self.object = form.save()
        forms.instance = self.object
        forms.save()
        return redirect('/units/list')
    else:
        return self.render_to_response(self.get_context_data(form=form))
def get_success_url(self):
    return self.success_url
template:
<h4 class="ui divinding header">Preços por região</h4>
 <table id="unit-table" class="ui small table">
            <thead>
            <tr>
                <th>Região</th>
                <th>Imagens</th>
                <th>Fixa: 1a região</th>
                <th>Demais regiões</th>
                <th>Móvel: 1a região</th>
                <th>Demais regiões</th>
            </tr>
            </thead>
            <tbody>
            {% for region in object_list %}
                <tr>
                    <td>
                            {{ region.name }}
                        </a>
                    </td>
                    <td>
                            {{ region.num_images }}
                    </td>
                    <td>
                        {{ region.price_1fix }}
                    </td>
                    <td>
                        {{ region.price_2fix }}
                    </td>
                    <td>
                        {{ region.price_1 }}
                    </td>
                    <td>
                        {{ region.price_2 }}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
 </table>
The fields of this form will be shown in this table.