mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduce local ChoiceField and MultipleChoiceField classes
This commit is contained in:
@@ -9,11 +9,13 @@ from utilities.forms import widgets
|
||||
from utilities.validators import EnhancedURLValidator
|
||||
|
||||
__all__ = (
|
||||
'ChoiceField',
|
||||
'ColorField',
|
||||
'CommentField',
|
||||
'JSONField',
|
||||
'LaxURLField',
|
||||
'MACAddressField',
|
||||
'MultipleChoiceField',
|
||||
'SlugField',
|
||||
'TagFilterField',
|
||||
)
|
||||
@@ -125,3 +127,21 @@ class MACAddressField(forms.Field):
|
||||
raise forms.ValidationError(self.error_messages['invalid'], code='invalid')
|
||||
|
||||
return value
|
||||
|
||||
|
||||
#
|
||||
# Choice fields
|
||||
#
|
||||
|
||||
class ChoiceField(forms.ChoiceField):
|
||||
"""
|
||||
Overrides Django's built-in `ChoiceField` to use NetBox's `StaticSelect` widget
|
||||
"""
|
||||
widget = widgets.StaticSelect
|
||||
|
||||
|
||||
class MultipleChoiceField(forms.MultipleChoiceField):
|
||||
"""
|
||||
Overrides Django's built-in `MultipleChoiceField` to use NetBox's `StaticSelectMultiple` widget
|
||||
"""
|
||||
widget = widgets.StaticSelectMultiple
|
||||
|
@@ -88,9 +88,10 @@ class StaticSelect(forms.Select):
|
||||
|
||||
|
||||
class StaticSelectMultiple(StaticSelect, forms.SelectMultiple):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
"""
|
||||
Extends `StaticSelect` to support multiple selections.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class SelectWithPK(StaticSelect):
|
||||
|
Reference in New Issue
Block a user