Ticket #18391: inline_form_custom_field.patch

File inline_form_custom_field.patch, 867 bytes (added by max@…, 3 years ago)

patch to fix inline forms and custom field types

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 5fcf959..c5afc08 100644
    a b class BaseModelFormSet(BaseFormSet): 
    431431
    432432    def _existing_object(self, pk):
    433433        if not hasattr(self, '_object_dict'):
    434             self._object_dict = dict([(o.pk, o) for o in self.get_queryset()])
     434            from django.db import connections
     435            self._object_dict = {}
     436            dct = self._object_dict
     437            for o in self.get_queryset():
     438                d_key = self.model._meta.pk.get_db_prep_lookup('exact', o.pk, connection=connections[self.get_queryset().db])
     439                if isinstance(d_key, list):
     440                    d_key = d_key[0]
     441                dct[d_key] = o
    435442        return self._object_dict.get(pk)
    436443
    437444    def _construct_form(self, i, **kwargs):
Back to Top