C
C
cozstate2015-02-20 14:21:33
Django
cozstate, 2015-02-20 14:21:33

Why is the parent form inline formset not displayed?

class ExchangeRate(StampedModel):
    document = models.ForeignKey(DocExchangeRate)
    # another fields

ExchangeInlineFormset = inlineformset_factory(DocExchangeRate, ExchangeRate, fk_name='document', extra=1)

class DocExchangeRateCreateView(CreateView):
    model = DocExchangeRate

    def get(self, request, *args, **kwargs):
        from django.shortcuts import render
        self.object = None
        formset = ExchangeInlineFormset()
        return render(request, 'pricing/docexchangerate_form.html', self.get_context_data(formset=formset))

<form action="" method="post">{% csrf_token %}
        {{ form }}
        {{ formset.management_form }}
        {{ formset }}
        <input type="submit" class="submit"/>
    </form>

the inline formset is rendered, and after clicking submit, the main form is rendered. How to bring them together?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cozstate, 2015-02-20
@cozstate

It turns out it is necessary to explicitly transfer to the context and the main form.
I was wrong in assuming that CBV will do this as well if get is not overridden.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question