Wrap call to key() in list() so it can be indexed

In Python 3.4 trying to generate a polymorphic_inlineformset results in a TypeError with the following message: "'KeysView' object does not support indexing". This solves that problem by ensuring that `child_models` is a list, and thus can be referenced by index.
This commit is contained in:
Chris Brantley
2016-09-21 09:56:20 -05:00
committed by GitHub
parent badad18a63
commit 8043e87b30
+1 -1
View File
@@ -180,7 +180,7 @@ class BasePolymorphicModelFormSet(BaseModelFormSet):
# Extra forms, cycle between all types # Extra forms, cycle between all types
# TODO: take the 'extra' value of each child formset into account. # TODO: take the 'extra' value of each child formset into account.
total_known = len(self.queryset_data) total_known = len(self.queryset_data)
child_models = self.child_forms.keys() child_models = list(self.child_forms.keys())
model = child_models[(i - total_known) % len(child_models)] model = child_models[(i - total_known) % len(child_models)]
form_class = self.get_form_class(model) form_class = self.get_form_class(model)