diff --git a/docs/plugins/development/filtersets.md b/docs/plugins/development/filtersets.md index cc847660d..cfaf9316b 100644 --- a/docs/plugins/development/filtersets.md +++ b/docs/plugins/development/filtersets.md @@ -32,6 +32,14 @@ class MyFilterSet(NetBoxModelFilterSet): fields = ('some', 'other', 'fields') ``` +In addition to the base NetBoxModelFilterSet class, the following filterset classes are also available for applicable models. + +| Model Class | FilterSet Class | +|-----------------------|--------------------------------------------------| +| `PrimaryModel` | `netbox.filtersets.PrimaryModelFilterSet` | +| `OrganizationalModel` | `netbox.filtersets.OrganizationalModelFilterSet` | +| `NestedGroupModel` | `netbox.filtersets.NestedGroupModelFilterSet` | + ### Declaring Filter Sets To utilize a filter set in a subclass of one of NetBox's generic views (such as `ObjectListView` or `BulkEditView`), define the `filterset` attribute on the view class: diff --git a/docs/plugins/development/models.md b/docs/plugins/development/models.md index eb12204ff..005248ae5 100644 --- a/docs/plugins/development/models.md +++ b/docs/plugins/development/models.md @@ -67,6 +67,24 @@ class MyModel(ExportTemplatesMixin, TagsMixin, models.Model): ... ``` +## Additional Models + +In addition to the base NetBoxModel class, the following additional classes are provided for convenience. + +!!! info "These base classes were added to the plugins API in NetBox v4.5." + +### PrimaryModel + +PrimaryModel is the go-to class for most object types. It extends NetBoxModel with `description` and `comments` fields, and it introduces support for ownership assignment. + +### OrganizationalModel + +OrganizationalModel is used by object types whose function is primarily the organization of other objects. It adds to NetBoxModel fields for `name`, `slug`, and `description`. It also supports ownership assignment. + +### NestedGroupModel + +NestedGroupModel is used for objects which arrange into a recursive hierarchy (like regions and locations) via its self-referential `parent` foreign key. It adds to NetBoxModel fields for `name`, `slug`, `description`, and `comments`. It also supports ownership assignment. + ## Database Migrations Once you have completed defining the model(s) for your plugin, you'll need to create the database schema migrations. A migration file is essentially a set of instructions for manipulating the PostgreSQL database to support your new model, or to alter existing models. Creating migrations can usually be done automatically using Django's `makemigrations` management command. (Ensure that your plugin has been installed and enabled first, otherwise it won't be found.) diff --git a/docs/plugins/development/rest-api.md b/docs/plugins/development/rest-api.md index 8cb5b3713..7b445d9a8 100644 --- a/docs/plugins/development/rest-api.md +++ b/docs/plugins/development/rest-api.md @@ -27,6 +27,14 @@ Serializers are responsible for converting Python objects to JSON data suitable The default nested representation of an object is defined by the `brief_fields` attributes under the serializer's `Meta` class. (Older versions of NetBox required the definition of a separate nested serializer.) +In addition to the base NetBoxModelSerializer class, the following serializer classes are also available for applicable models. + +| Model Class | Serializer Class | +|-----------------------|--------------------------------------------------------| +| `PrimaryModel` | `netbox.api.serializers.PrimaryModelSerializer` | +| `OrganizationalModel` | `netbox.api.serializers.OrganizationalModelSerializer` | +| `NestedGroupModel` | `netbox.api.serializers.NestedGroupModelSerializer` | + #### Example To create a serializer for a plugin model, subclass `NetBoxModelSerializer` in `api/serializers.py`. Specify the model class and the fields to include within the serializer's `Meta` class. diff --git a/docs/plugins/development/tables.md b/docs/plugins/development/tables.md index ea36b204d..70040f8ea 100644 --- a/docs/plugins/development/tables.md +++ b/docs/plugins/development/tables.md @@ -36,6 +36,14 @@ class MyModelTable(NetBoxTable): default_columns = ('pk', 'name', ...) ``` +In addition to the base NetBoxTable class, the following table classes are also available for applicable models. + +| Model Class | Serializer Class | +|-----------------------|------------------------------------------| +| `PrimaryModel` | `netbox.tables.PrimaryModelTable` | +| `OrganizationalModel` | `netbox.tables.OrganizationalModelTable` | +| `NestedGroupModel` | `netbox.tables.NestedGroupModelTable` | + ### Table Configuration The NetBoxTable class features dynamic configuration to allow users to change their column display and ordering preferences. To configure a table for a specific request, simply call its `configure()` method and pass the current HTTPRequest object. For example: