From caebc92f6e7f0a3e8445d054edd5587c58920c76 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 1 Sep 2016 18:49:14 +0200 Subject: Non-available types display on old item modification (refs #3179) --- ishtar_common/models.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index e2142ef0c..04077b240 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -330,7 +330,28 @@ class GeneralType(Cached, models.Model): @classmethod def get_types(cls, dct={}, instances=False, exclude=[], empty_first=True, - default=None): + default=None, initial=None): + types = cls.pre_get_types(dct, instances, exclude, empty_first, + default) + if not initial: + return types + for value in initial: + try: + pk = int(value) + except ValueError: + continue + if pk in [idx for idx, lbl in types]: + continue + try: + extra_type = cls.objects.get(pk=pk) + types.append((extra_type.pk, unicode(extra_type))) + except cls.DoesNotExist: + continue + return types + + @classmethod + def pre_get_types(cls, dct={}, instances=False, exclude=[], + empty_first=True, default=None): # cache cache_key = None if not instances: -- cgit v1.2.3