Procházet zdrojové kódy

Rename fail() kwarg from attr to field

jeremystretch před 4 roky
rodič
revize
f81b3d4ed6

+ 1 - 1
docs/additional-features/custom-validation.md

@@ -41,7 +41,7 @@ from extras.validators import CustomValidator
 class MyValidator(CustomValidator):
 class MyValidator(CustomValidator):
     def validate(self, instance):
     def validate(self, instance):
         if instance.status == 'active' and not instance.description:
         if instance.status == 'active' and not instance.description:
-            self.fail("Active sites must have a description set!", attr='status')
+            self.fail("Active sites must have a description set!", field='status')
 ```
 ```
 
 
 The `fail()` method may optionally specify a field with which to associate the supplied error message. If specified, the error message will appear to the user as associated with this field. If omitted, the error message will not be associated with any field.
 The `fail()` method may optionally specify a field with which to associate the supplied error message. If specified, the error message will appear to the user as associated with this field. If omitted, the error message will not be associated with any field.

+ 4 - 4
netbox/extras/validators.py

@@ -63,10 +63,10 @@ class CustomValidator:
         """
         """
         return
         return
 
 
-    def fail(self, message, attr=None):
+    def fail(self, message, field=None):
         """
         """
-        Raise a ValidationError exception. Associate the provided message with an attribute if specified.
+        Raise a ValidationError exception. Associate the provided message with a form/serializer field if specified.
         """
         """
-        if attr is not None:
-            raise ValidationError({attr: message})
+        if field is not None:
+            raise ValidationError({field: message})
         raise ValidationError(message)
         raise ValidationError(message)