[patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW
Description
- Because there is a bug here 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
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
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
...
{% 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 ..'
Change History
(10)
Summary: |
InlineObjectCollection error when editinline objects using default AddManipulators with FOLLOW → KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW
|
milestone: |
Version 0.93 → Version 1.0
|
Summary: |
KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW → [patch] KeyError encountered when edit_inline objects using default AddManipulators with some fields equals False in FOLLOW
|
Component: |
Template system → Core framework
|
Needs tests: |
set
|
Triage Stage: |
Unreviewed → Accepted
|
Version: |
magic-removal → SVN
|
Resolution: |
→ wontfix
|
Status: |
new → closed
|
0.93 has come and gone.