﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
2434	[patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW	chengqi@…	nobody	"= Description =

 * Because there is a bug here [http://code.djangoproject.com/ticket/2424 ticket2424], so I've to custom manipulators to save objects with editinlie issues.
 * Then there is another bug here: 
    * when using default manipulators to save objects together with edit_inline objects, if I want to suppress one field of the related objects, I have to use follow keywords(right?), then it always throw !KeyError. 
    * e.g, take the model(Poll/Choice) in django's tutorial1, if want to suppress the 'votes' field of each Choice object when saving a poll, I should use Poll.AddManipulator(follow={'choice': {'votes': False}}), then it will thrown KeyError of 'choice.0.vote' not found while rending the templates. 
    * It is the django/forms/__init__.py:InlineObjectCollection class that lead to the error. Because I have suppressed the votes field in the manipulaor, so there are no votes fields in the manipulator. But the InlineObjectCollection doesn't refer to the follow parameters, it just loop over all the editable fields. So the bug is encountered.
    * The followings are my codes and my patch.

= Codes =
== Model ==
{{{
#!python
from django.db import models

class Poll(models.Model):
    question = models.CharField(maxlength=200)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(maxlength=200)
    votes = models.IntegerField()
    field_to_suppress = models.IntegetField()
}}}
== View ==
{{{
#!python
def view(request):
    ...
    manipulator = Poll.AddManipulator(follow={'choice': {'field_to_suppress': False}})
    ....
    form = forms.FormWrapper(manipulator, new_data, errors)
    c_ = template.RequestContext(request, {
        'form': form
        })
    return render_to_response('templates.html', c_)
}}}
== templates ==
{{{
#!python
...
{% for choice_ in form.choices %}
  {{ choice.votes }}
  {{ choice.choice }}
{% endfor %}
...
}}}

= Steps to reproduce =
 * Try to add a Poll
 * Then the line {% for choice_ in form.choices %} will throw errors of 'Key choice.0.field_to_suppress not found in [..]' 

"	defect	closed	Core (Other)	dev	normal	wontfix			Accepted	1	0	1	0	0	0
