From f7a54d5ee7c111da1819e1e92d4e5957d31c4e48 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 26 Nov 2015 19:02:08 +0100 Subject: Wizard: allow callable to be keys --- ishtar_common/wizards.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ishtar_common/wizards.py') diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 21cfa6ceb..180ed4618 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -408,6 +408,8 @@ class Wizard(NamedUrlWizardView): return self.render(form_list[-1]) for dependant_item in other_objs: c_item = getattr(obj, dependant_item) + if callable(c_item): + c_item = c_item() # manage ManyToMany if only one associated if hasattr(c_item, "all"): c_items = c_item.all() @@ -781,10 +783,12 @@ class Wizard(NamedUrlWizardView): if base_model: key = base_model + 's' initial.setlist(base_field, [ - unicode(val.pk) for val in getattr(obj, key).all()]) + unicode(val.pk) for val in getattr(value, key).all()]) else: fields = base_field.split('__') for field in fields: + if callable(value): + value = value() if not hasattr(value, field) or \ getattr(value, field) is None: value = obj -- cgit v1.2.3