FilteredSelectionFormOptions updates

Fix displaying the name of the subclass when the
queryset is missing.

Add support for passing a new argument to specify
if the field is required or not.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-01-22 22:35:37 -04:00
parent a769cc92e3
commit 1d0ebbab64

View File

@@ -141,6 +141,7 @@ class FilteredSelectionFormOptions(object):
{'model': None},
{'permission': None},
{'queryset': None},
{'required': True},
{'user': None},
{'widget_class': None},
{'widget_attributes': {'size': '10'}},
@@ -191,7 +192,7 @@ class FilteredSelectionForm(forms.Form):
raise ImproperlyConfigured(
'{} requires a queryset or a model to be specified as '
'a meta option or passed during initialization.'.format(
self.__class__
self.__class__.__name__
)
)
@@ -221,7 +222,7 @@ class FilteredSelectionForm(forms.Form):
self.fields[opts.field_name] = field_class(
help_text=opts.help_text, label=opts.label,
queryset=queryset, required=True,
queryset=queryset, required=opts.required,
widget=widget_class(attrs=opts.widget_attributes),
**extra_kwargs
)