From 125d2f5e3f17b3ee3b4813bebff8afe5968b6153 Mon Sep 17 00:00:00 2001 From: Kevi Nasto Date: Fri, 13 Mar 2020 11:24:20 -0500 Subject: [PATCH 1/2] If value is filtered out in the queryset, try the other values before returning None which fixes validation error --- selectable/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/selectable/base.py b/selectable/base.py index 9570a19..ce38516 100644 --- a/selectable/base.py +++ b/selectable/base.py @@ -153,6 +153,10 @@ def get_item(self, value): try: item = self.get_queryset().get(pk=value) except (ValueError, self.model.DoesNotExist): + try: # Check the rest of the values before returning None + item = self.model.objects.get(pk=value) + except (ValueError, self.model.DoesNotExist): + pass item = None return item From 0191637f1300e089b36ff61ad045cdc69be8b26d Mon Sep 17 00:00:00 2001 From: Kevi Nasto Date: Fri, 13 Mar 2020 12:00:17 -0500 Subject: [PATCH 2/2] Item = None needs to be before the try and except so it doesnt get overwrite it --- selectable/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selectable/base.py b/selectable/base.py index ce38516..534a4a6 100644 --- a/selectable/base.py +++ b/selectable/base.py @@ -153,11 +153,11 @@ def get_item(self, value): try: item = self.get_queryset().get(pk=value) except (ValueError, self.model.DoesNotExist): + item = None try: # Check the rest of the values before returning None item = self.model.objects.get(pk=value) except (ValueError, self.model.DoesNotExist): pass - item = None return item def create_item(self, value):