diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-09-22 17:41:48 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-09-22 17:44:26 +0200 |
commit | da02ccba709cc0688f5964c8b703d18f9edfd87d (patch) | |
tree | b4b55acfd796a325da3145015e17bd5245a8e5d3 /ishtar_common/lookups.py | |
parent | 50dc8148259f6c36890c29d4b6f487a85ff7efa1 (diff) | |
download | Ishtar-da02ccba709cc0688f5964c8b703d18f9edfd87d.tar.bz2 Ishtar-da02ccba709cc0688f5964c8b703d18f9edfd87d.zip |
Admin: fix import edit
Diffstat (limited to 'ishtar_common/lookups.py')
-rw-r--r-- | ishtar_common/lookups.py | 23 |
1 files changed, 20 insertions, 3 deletions
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"<span class='ajax-label'>%s</span>" % str(item) + return "<span class='ajax-label'>%s</span>" % 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"<span class='ajax-label'>%s</span>" % str(item.person) + return "<span class='ajax-label'>%s</span>" % str(item.person) @register('area') |