diff options
Diffstat (limited to 'ishtar_common/forms.py')
| -rw-r--r-- | ishtar_common/forms.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 4db6a138b..416a1a9ec 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -707,8 +707,8 @@ class FieldType: self.empty_first = empty_first self.help_text = help_text - def get_choices(self, initial=None): - args = {"empty_first": self.empty_first, "initial": initial} + def get_choices(self, initial=None, limit=None): + args = {"empty_first": self.empty_first, "initial": initial, "limit": limit} if self.extra_args: args.update(self.extra_args) return self.model.get_types(**args) @@ -848,10 +848,14 @@ class IshtarForm(BSForm, forms.Form): for field in type_lst: self._init_type(field) - def _init_type(self, field): + def _init_type(self, field, extra=None): if field.key not in self.fields: return - self.fields[field.key].choices = field.get_choices() + if not extra: + extra = {} + if hasattr(self, "limits") and field.key in self.limits: + extra["limit"] = self.limits[field.key] + self.fields[field.key].choices = field.get_choices(**extra) if not getattr(field, "help_text", True): return self.fields[field.key].help_text = field.get_help() @@ -1349,10 +1353,7 @@ class ManageOldType(IshtarForm): if field.key not in self.fields: return initial = self.init_data.getlist(field.key) - self.fields[field.key].choices = field.get_choices( - initial=initial - ) - self.fields[field.key].help_text = field.get_help() + super()._init_type(field, extra={"initial": initial}) class QAForm(CustomForm, ManageOldType): |
