Code

Ticket #10015: 10015_r9729.diff

File 10015_r9729.diff, 902 bytes (added by carljm, 5 years ago)

fix by introspection of ct_fk_field in BaseGenericInlineFormset

Line 
1Index: django/contrib/contenttypes/generic.py
2===================================================================
3--- django/contrib/contenttypes/generic.py      (revision 9729)
4+++ django/contrib/contenttypes/generic.py      (working copy)
5@@ -310,9 +310,14 @@
6             return self.model._default_manager.empty()
7         return self.model._default_manager.filter(**{
8             self.ct_field.name: ContentType.objects.get_for_model(self.instance),
9-            self.ct_fk_field.name: self.instance.pk,
10+            self.ct_fk_field.name: self._cast_instance_pk(self.instance.pk),
11         })
12 
13+    def _cast_instance_pk(self, pk):
14+        if self.ct_fk_field.get_internal_type() == 'TextField':
15+            return smart_unicode(pk)
16+        return pk
17+
18     def save_new(self, form, commit=True):
19         # Avoid a circular import.
20         from django.contrib.contenttypes.models import ContentType