Monday, September 1, 2014

Re: crispy forms two forms and context

It looks like you are passing the context an actual Answers object, not a Form or ModelForm object that will add/update an Answers object, hence the reason the trace back complains about a lack of 'fields'.

-James

On Monday, September 1, 2014, Brad Rice <bradrice1@gmail.com> wrote:
This document seems to indicate I can have two forms inside one set of form tags:


I cannot figure out how to set the context to be able to iterate over both forms.

{% crispy form %}

works on my model form.

If I try to set context in my view like this:

def get_context_data(self, **kwargs):
        context = super(ApplicationVerify, self).get_context_data(**kwargs)
        context['app'] = Application.objects.get(id=self.kwargs['app_id'])
        context['answers'] = Answers.objects.get(created_by=self.request.user)
        context['applicant'] = Applicant.objects.get(created_by=self.request.user)
        return context

and then use instead of crispy form

{% crispy answers %}

I get errors.

'Answers' object has no attribute 'fields'

How do I set a form to have context from several models?

I do see the context is coming into the template, it just is not treating them as having form widgets.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV9EY2dxtBNk_or3iMp%3DtQuSG6HKnoDdY2XMtJu46VOaA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment