Add fields to restrict visibility/creation of custom fields #3852

Closed
opened 2025-12-29 18:31:36 +01:00 by adam · 2 comments
Owner

Originally created by @shane-davidson on GitHub (Jul 10, 2020).

Environment

  • Python version: 3.8.2
  • NetBox version: 2.8

Proposed Functionality

Adding an option in custom fields to restrict the custom field visibility based on the model fields equality a specific value.

class CustomField(models.Model):

    restrict= models.CharField(
        default=None,
       choices= "custom choice set showing fields available for filtering"
        help_text='Model field used to restrict visibility of this custom field.'
    )

    restrict_value= models.CharField(
        blank=True,
        help_text='Value to match when restrict field is set'
    )

    restrict_negate= models.BooleanField(
        blank=True,
        help_text='Negates restriction match'
    )

when creating a custom field you have the option to select a field and a value to match.
This field and value will decide if the custom field is visible or not.

Use Case

Create a role for a virtual machine called "app server"
Create a custom field you only want visible on virtual machine with the "app server" role

restrict = "role.name"
restrict_value = "app server"

Create a role for a virtual machine called "database server"
Create a custom field you only want visible on virtual machine with the "database server" role

restrict = "role.name"
restrict_value = "database server"

Create a device with type "Cisco Router"
Create a custom field on device

restrict = "device_type.manufacturer.name"
restrict_value = "Cisco"

OR

restrict = "device_type.manufacturer.model"
restrict_value = "Cisco Router XXX"

Other considerations:

  • Optional negate on the restriction.
  • Setting for if new 'restrict' field doesn't match any model field to show or hide the custom fields

Database Changes

New fields on CustomField

External Dependencies

None

Originally created by @shane-davidson on GitHub (Jul 10, 2020). ### Environment * Python version: 3.8.2 * NetBox version: 2.8 ### Proposed Functionality Adding an option in custom fields to restrict the custom field visibility based on the model fields equality a specific value. ``` class CustomField(models.Model): restrict= models.CharField( default=None, choices= "custom choice set showing fields available for filtering" help_text='Model field used to restrict visibility of this custom field.' ) restrict_value= models.CharField( blank=True, help_text='Value to match when restrict field is set' ) restrict_negate= models.BooleanField( blank=True, help_text='Negates restriction match' ) ``` when creating a custom field you have the option to select a field and a value to match. This field and value will decide if the custom field is visible or not. ### Use Case Create a role for a virtual machine called "app server" Create a custom field you only want visible on virtual machine with the "app server" role ``` restrict = "role.name" restrict_value = "app server" ``` Create a role for a virtual machine called "database server" Create a custom field you only want visible on virtual machine with the "database server" role ``` restrict = "role.name" restrict_value = "database server" ``` Create a device with type "Cisco Router" Create a custom field on device ``` restrict = "device_type.manufacturer.name" restrict_value = "Cisco" ``` OR ``` restrict = "device_type.manufacturer.model" restrict_value = "Cisco Router XXX" ``` Other considerations: - Optional negate on the restriction. - Setting for if new 'restrict' field doesn't match any model field to show or hide the custom fields ### Database Changes New fields on CustomField ### External Dependencies None
adam closed this issue 2025-12-29 18:31:36 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 10, 2020):

We are not currently accepting feature requests for development related to custom fields.

@jeremystretch commented on GitHub (Jul 10, 2020): We are not currently accepting feature requests for development related to custom fields.
Author
Owner

@jeremystretch commented on GitHub (Jul 22, 2020):

Please see #4878

@jeremystretch commented on GitHub (Jul 22, 2020): Please see #4878
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3852