Skip to content

Simplify the declaration of custom field support in models #8373

@jeremystretch

Description

@jeremystretch

Proposed Changes

Currently, a NetBox model must meet two conditions for custom fields to function properly:

  1. Inherit from CustomFieldsMixin
  2. Register as having custom fields via the extras_features() decorator

The second step is redundant, given that it should be assumed that any model inheriting from CustomFieldsMixin supports custom fields. However, failing to register via extras_features() excludes the model from the list of available models when creating a custom field, and from other such selections.

We can obviate the need to register the model explicitly by instead connecting a receiver function to Django's class_prepared signal and checking for custom field support on the class.

Justification

Eliminates redundant code and reduces the possibility for human error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: housekeepingChanges to the application which do not directly impact the end user

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions