mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
test fix. allow validated model serializer to specify certain fields to ignore validation on.
This commit is contained in:
parent
2335b90e29
commit
a621912396
@ -696,6 +696,9 @@ class WritableInterfaceSerializer(ValidatedModelSerializer):
|
|||||||
'id', 'device', 'name', 'form_factor', 'enabled', 'lag', 'mtu', 'mac_address', 'mgmt_only', 'description',
|
'id', 'device', 'name', 'form_factor', 'enabled', 'lag', 'mtu', 'mac_address', 'mgmt_only', 'description',
|
||||||
'mode', 'untagged_vlan', 'tagged_vlans',
|
'mode', 'untagged_vlan', 'tagged_vlans',
|
||||||
]
|
]
|
||||||
|
ignore_validation_fields = [
|
||||||
|
'tagged_vlans'
|
||||||
|
]
|
||||||
|
|
||||||
def validate(self, data):
|
def validate(self, data):
|
||||||
|
|
||||||
|
@ -48,6 +48,11 @@ class ValidatedModelSerializer(ModelSerializer):
|
|||||||
attrs = data.copy()
|
attrs = data.copy()
|
||||||
attrs.pop('custom_fields', None)
|
attrs.pop('custom_fields', None)
|
||||||
|
|
||||||
|
# remove any fields marked for no validation
|
||||||
|
ignore_validation_fields = getattr(self.Meta, 'ignore_validation_fields', [])
|
||||||
|
for field in ignore_validation_fields:
|
||||||
|
attrs.pop(field)
|
||||||
|
|
||||||
# Run clean() on an instance of the model
|
# Run clean() on an instance of the model
|
||||||
if self.instance is None:
|
if self.instance is None:
|
||||||
instance = self.Meta.model(**attrs)
|
instance = self.Meta.model(**attrs)
|
||||||
|
Loading…
Reference in New Issue
Block a user