python - key error value 0 on modelformset when queryset is empty -


i want create multiple instances of model using modelformset. when queryset empty , parameter extra greater 0 raises error:

    environment:   request method: request url: http://localhost:8000/alta_socies/proces_alta_projecte_autoocupat/adreces/  django version: 1.7.7 python version: 2.7.9 installed applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.formtools', 'inici', 'alta_socies', 'empreses', 'socies') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.common.commonmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.auth.middleware.sessionauthenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'django.middleware.clickjacking.xframeoptionsmiddleware')   template error: in template /home/usergci/gestioci/alta_socies/templates/alta_socies/proces_alta_autoocupat.html, error @ line 59    0    49 :     <div class="row">      50 :         <div class="medium-12 columns content">      51 :             <div class="row">      52 :                 <div class="medium-12 columns">      53 :                     <div class="group">      54 :                         <h2>{{ projecte.pas }}</h2>      55 :                         {% block explicacio_pas %}{% endblock %}      56 :                     </div>      57 :                     <form method="post" action="">{% csrf_token %}      58 :                     {{ wizard.management_form }}      59 :                      {% if wizard.form.forms %}      60 :                             {{ wizard.form.management_form }}      61 :                         {% form in wizard.form.forms %}      62 :                             {% block step_factory_form %}      63 :                             {% endblock %}      64 :                         {% endfor %}      65 :                     {% else %}      66 :                         {% block step_single_form %}      67 :                         {% endblock %}      68 :                     {% endif %}      69 :                     <input class="small radius button" type="submit" name="save_only" value="guardar y salir"/>   traceback: file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response   137.                 response = response.render() file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/response.py" in render   103.             self.content = self.rendered_content file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content   80.         content = template.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   148.             return self._render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in _render   142.         return self.nodelist.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render   126.         return compiled_parent._render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in _render   142.         return self.nodelist.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render   126.         return compiled_parent._render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in _render   142.         return self.nodelist.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render   126.         return compiled_parent._render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in _render   142.         return self.nodelist.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render   402.         return strip_spaces_between_tags(self.nodelist.render(context).strip()) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render   65.                 result = block.nodelist.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render   65.                 result = block.nodelist.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in render   844.                 bit = self.render_node(node, context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/debug.py" in render_node   80.             return node.render(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render   305.                     match = condition.eval(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/defaulttags.py" in eval   898.         return self.value.resolve(context, ignore_failures=true) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in resolve   596.                 obj = self.var.resolve(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in resolve   734.             value = self._resolve_lookup(context) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup   770.                         current = getattr(current, bit) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/utils/functional.py" in __get__   55.         res = instance.__dict__[self.func.__name__] = self.func(instance) file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/forms/formsets.py" in forms   141.         forms = [self._construct_form(i) in xrange(self.total_form_count())] file "/home/usergci/.virtualenvs/heteroceras/local/lib/python2.7/site-packages/django/forms/models.py" in _construct_form   591.                 kwargs['initial'] = self.initial_extra[i - self.initial_form_count()]  exception type: keyerror @ /alta_socies/proces_alta_projecte_autoocupat/adreces/ exception value: 0 

the offending lines far debugged are:

    adrecesformset = modelformset_factory(adrecaprojecteautoocupat,                                       form=formulariadrecaprojecteautoocupat,                                       can_delete=true) 

any hint?

the wizard form expecting list of dicts intead of dict!!! problem somewhere else in views.py


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -