I wrote an app that allows people to login to fill out an application. It 
has quite a few text areas that have to be filled out, so the idea was to 
allow them to fill out partial and come back and work on it and eventually 
submit it. The last stage before submit I pull all the data into a final 
form and allow them to submit it if they are satisfied. It set's required 
on the fields at that stage. There are three related db tables (models). So 
maybe, I'm thinking about this wrong. Instead of having two or three forms 
on a single page, maybe I need to built one from from the three related 
models at the end.

On Monday, September 1, 2014 8:45:05 PM UTC-4, James Schneider wrote:
>
> I would assume you want something akin to the first example here:
>
> https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
>
> Once you have the form object built with the instance of your Answer 
> object, just pass it along.
>
> Since I've never needed more than one form on a page, there may be other 
> gotchas, but you should be able to Google for those. I don't believe that 
> you'll need to do anything special though. Keep in mind that only one of 
> the forms will be submitted (assuming each has it's own set of <form> 
> tags). If you need to combine them and submit info for both, you may need 
> to roll a single custom form class that can handle all of the data, or 
> possibly look into Django formsets.
>
> -James
>
>
> On Monday, September 1, 2014, Brad Rice <brad...@gmail.com <javascript:>> 
> wrote:
>
>> Here is my entire view class to go with a ModelForm. How do I get the 
>> various forms as context into my template?
>>
>> class ApplicationVerify(UpdateView):
>>     model = Answers
>>     form_class = ApplicationCheckForm
>>     template_name = 'requestform/application_detail.html'
>>
>>     @method_decorator(login_required(login_url='/accounts/login/'))
>>     def dispatch(self, *args, **kwargs):
>>         return super(ApplicationVerify, self).dispatch(*args, **kwargs)
>>
>>     def get_object(self, queryset=None):
>>         return Answers.objects.get(created_by=self.request.user)
>>
>>     def form_valid(self, form):
>>         obj = form.save(commit=False)
>>         obj.created_by = self.request.user
>>         obj.save()
>>         a = Application.objects.get(created_by=self.request.user)
>>         b = Answers.objects.get(created_by=self.request.user)
>>         c = Applicant.objects.get(created_by=self.request.user)
>>         return HttpResponseRedirect(reverse('requestform:app_complete', 
>> kwargs={'app_id': a.id}))
>>
>>
>>     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
>>
>> On Monday, September 1, 2014 4:15:39 PM UTC-4, James Schneider wrote:
>>>
>>> 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 <brad...@gmail.com> wrote:
>>>
>>>> This document seems to indicate I can have two forms inside one set of 
>>>> form tags:
>>>>
>>>> http://django-crispy-forms.readthedocs.org/en/latest/
>>>> crispy_tag_forms.html#rendering-several-forms-with-helpers
>>>>
>>>> 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+unsubscr...@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 
>>>> <https://groups.google.com/d/msgid/django-users/9845f147-8c82-49fd-b15a-62e79680caa2%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> 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+unsubscr...@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/ae25d932-a31b-4a23-aac3-4b9920fb710e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/ae25d932-a31b-4a23-aac3-4b9920fb710e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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+unsubscr...@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/a0061d92-35d2-4951-ac70-d07d28057fe7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to