From c83730b93629b2a2a94d40faf770885776299b16 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 22 Sep 2020 17:41:48 +0200 Subject: Admin: fix import edit --- ishtar_common/lookups.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'ishtar_common/lookups.py') diff --git a/ishtar_common/lookups.py b/ishtar_common/lookups.py index e2e9251e7..3481ba1a9 100644 --- a/ishtar_common/lookups.py +++ b/ishtar_common/lookups.py @@ -15,10 +15,27 @@ class LookupChannel(BaseLookupChannel): ids.append(item.pk) else: ids.append(item) - return super(LookupChannel, self).get_objects(ids) + + # TODO: strange bug on Import edit + # copied from lookup_channel.py + if getattr(self.model._meta.pk, "remote_field", False): + # Use the type of the field being referenced (2.0+) + # modification is here + # pk_type = self.model._meta.pk.remote_field.field.to_python + pk_type = int + elif getattr(self.model._meta.pk, "rel", False): + # Use the type of the field being referenced + pk_type = self.model._meta.pk.rel.field.to_python + else: + pk_type = self.model._meta.pk.to_python + + # Return objects in the same order as passed in here + ids = [pk_type(pk) for pk in ids] + things = self.model.objects.in_bulk(ids) + return [things[aid] for aid in ids if aid in things] def format_item_display(self, item): - return u"%s" % str(item) + return "%s" % str(item) class TypeLookupChannel(LookupChannel): @@ -118,7 +135,7 @@ class UserLookup(LookupChannel): return self.model.objects.filter(query).order_by('person__name')[:20] def format_item_display(self, item): - return u"%s" % str(item.person) + return "%s" % str(item.person) @register('area') -- cgit v1.2.3