1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #15490: CustomValidator support for accessing related object attribute via dotted path

This commit is contained in:
Jeremy Stretch
2024-03-22 15:34:07 -04:00
parent 74444da7b8
commit 817e009e4f
2 changed files with 27 additions and 6 deletions

View File

@ -151,14 +151,14 @@ class CustomValidator:
return []
# Raise a ValidationError for unknown attributes
if not hasattr(instance, name):
try:
return operator.attrgetter(name)(instance)
except AttributeError:
raise ValidationError(_('Invalid attribute "{name}" for {model}').format(
name=name,
model=instance.__class__.__name__
))
return getattr(instance, name)
def get_validator(self, descriptor, value):
"""
Instantiate and return the appropriate validator based on the descriptor given. For