Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 24, 2011 23:38:41

Axel B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

modelformset not iterable


Hello all,

I am trying to implement something quite simple, in my eyes. But it does not
work at all ... . Basically, I create a modelformset_factory with a model of
mine, and pass the instantiated modelformset to my template to render. And I
get the message *Caught TypeError while rendering: 'LegFormFormSet' object
is not iterable ...* (note the *FormForm*-part in the error message? it
should be one "*Form*" only ... shouldn't it?)

The code looks like this:
def addlegs(request, mission_id=None):
*LegFormSet* = modelformset_factory(Leg, extra=3)
if not request.method == "POST":
# if mission_id is set we're being called from another method in
here ... :)
*formset = LegFormSet(queryset=Leg.objects.none())*
return rtr(request, 'flightlog/templates/addlegs.html', {*
"formset":formset*})
else:
return redirect("/")

and the template like this:
{% load widget_tweaks %}
<form method="post" action="/addlegs/">
{% csrf_token %}
{{ formset.management_form }}
<table>
{% for form in formset %}
{% for field in form %}
{{ field|add_class:"myclass" }}
{% endfor %}
{% endfor %}
</table>
<input type="submit" value="Save leg data"/>
</form>

in my eyes that's all pretty simple, but it drives me crazy right now cause
it does not work at all. in case you wonder: the management_form is rendered
correctly. The rendered code for this looks like this:
<input type="hidden" name="form-TOTAL_FORMS" value="3"
id="id_form-TOTAL_FORMS"/><input type="hidden"
name="form-INITIAL_FORMS"
value="0"
id="id_form-INITIAL_FORMS"/>
<input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS"/>


any ideas, anyone?


Thanks for any help & greetings,
Axel.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 24, 2011 23:48:07

Axel B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

modelformset not iterable


forget it. it was formset.forms ...
I *SWEAR* there is another example just with "for form in formset" ...

thanks anyway :)
Axel.



2011/1/25 Axel Bock <mr.axel.b...@gmail.com>

> Hello all,
>
> I am trying to implement something quite simple, in my eyes. But it does
> not work at all ... . Basically, I create a modelformset_factory with a
> model of mine, and pass the instantiated modelformset to my template to
> render. And I get the message *Caught TypeError while rendering: '
> LegFormFormSet' object is not iterable ...* (note the *FormForm*-part in
> the error message? it should be one "*Form*" only ... shouldn't it?)
>
> The code looks like this:
> def addlegs(request, mission_id=None):
> *LegFormSet* = modelformset_factory(Leg, extra=3)
> if not request.method == "POST":
> # if mission_id is set we're being called from another method in
> here ... :)
> *formset = LegFormSet(queryset=Leg.objects.none())*
> return rtr(request, 'flightlog/templates/addlegs.html', {*
> "formset":formset*})
> else:
> return redirect("/")
>
> and the template like this:
> {% load widget_tweaks %}
> <form method="post" action="/addlegs/">
> {% csrf_token %}
> {{ formset.management_form }}
> <table>
> {% for form in formset %}
> {% for field in form %}
> {{ field|add_class:"myclass" }}
> {% endfor %}
> {% endfor %}
> </table>
> <input type="submit" value="Save leg data"/>
> </form>
>
> in my eyes that's all pretty simple, but it drives me crazy right now cause
> it does not work at all. in case you wonder: the management_form is rendered
> correctly. The rendered code for this looks like this:
> <input type="hidden" name="form-TOTAL_FORMS" value="3"
> id="id_form-TOTAL_FORMS"/><input type="hidden"
> name="form-INITIAL_FORMS"
> value="0"
> id="id_form-INITIAL_FORMS"/>
> <input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS"/>
>
>
> any ideas, anyone?
>
>
> Thanks for any help & greetings,
> Axel.
>

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 25, 2011 06:17:31

Fabian E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

modelformset not iterable


2011/1/24 Axel Bock <mr.axel.b...@gmail.com>:
> forget it. it was formset.forms ...
> I *SWEAR* there is another example just with "for form in formset" ...
>
> thanks anyway :)
> Axel.
>

Probably in the documentation for the development version :)


Regards,
--
Fabián E. Gallinahttp://www.from-the-cloud.com--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 12th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support