I would like some help with messages in NetBox, please. I'm writing a custom validator and I need to display a warning message if for example a device name doesn't fit the company's policy. I can't use the standard fail method in the CustomValidator class - the edit request should be fulfilled, it's just supposed to warn the user as well. I would like to use a box message like this one, just with the warning level.
I tried something like this:
from extras.validators import CustomValidator
from django.contrib import messages
class device_validator(CustomValidator):
def validate(self, instance):
if instance.name is not instance.name.upper():
messages.info(request, "Names of devices should be in all-caps.")
return
But clearly, my syntax is wrong. I get the "Server Error" window and following message:
<class 'NameError'>
name 'request' is not defined
How do I define the request? Could someone please give me an example how to display a message in this context?
Thank you.