mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
Merge branch 'feature' into 10500-nested-modules
This commit is contained in:
commit
b7012a030d
@ -74,6 +74,8 @@ If a default value is specified for a selection field, it must exactly match one
|
||||
|
||||
An object or multi-object custom field can be used to refer to a particular NetBox object or objects as the "value" for a custom field. These custom fields must define an `object_type`, which determines the type of object to which custom field instances point.
|
||||
|
||||
By default, an object choice field will make all objects of that type available for selection in the drop-down. The list choices can be filtered to show only objects with certain values by providing a `query_params` dict in the Related Object Filter field, as a JSON value. More information about `query_params` can be found [here](./custom-scripts.md#objectvar).
|
||||
|
||||
## Custom Fields in Templates
|
||||
|
||||
Several features within NetBox, such as export templates and webhooks, utilize Jinja2 templating. For convenience, objects which support custom field assignment expose custom field data through the `cf` property. This is a bit cleaner than accessing custom field data through the actual field (`custom_field_data`).
|
||||
|
@ -42,6 +42,13 @@ The type of data this field holds. This must be one of the following:
|
||||
|
||||
For object and multiple-object fields only. Designates the type of NetBox object being referenced.
|
||||
|
||||
### Related Object Filter
|
||||
|
||||
For object and multi-object custom fields, a filter may be defined to limit the available objects when populating a field value. This filter maps object attributes to values. For example, `{"status": "active"}` will include only objects with a status of "active."
|
||||
|
||||
!!! warning
|
||||
This setting is employed for convenience only, and should not be relied upon to enforce data integrity.
|
||||
|
||||
### Weight
|
||||
|
||||
A numeric weight used to override alphabetic ordering of fields by name. Custom fields with a lower weight will be listed before those with a higher weight. (Note that weight applies within the context of a custom field group, if defined.)
|
||||
|
@ -6,16 +6,42 @@
|
||||
|
||||
* Several filters deprecated in v4.0 have been removed (see [#15410](https://github.com/netbox-community/netbox/issues/15410)).
|
||||
* The unit size for virtual disk size has been changed from 1 gigabyte to 1 megabyte. Existing values have been updated accordingly.
|
||||
* The `min_vid` and `max_vid` fields on the VLAN group model have been replaced with `vid_ranges`, an array of starting and ending integer pairs.
|
||||
* The `validate()` method on CustomValidator subclasses now **must** accept the request argument (deprecated in v4.0 by #14279).
|
||||
|
||||
### New Features
|
||||
|
||||
#### Circuit Groups ([#7025](https://github.com/netbox-community/netbox/issues/7025))
|
||||
|
||||
Circuits can now be assigned to groups for administrative purposes. Each circuit may be assigned to multiple groups, and each assignment may optionally indicate a priority (primary, secondary, or tertiary).
|
||||
|
||||
#### VLAN Group ID Ranges ([#9627](https://github.com/netbox-community/netbox/issues/9627))
|
||||
|
||||
The VLAN group model has been enhanced to support multiple VLAN ID (VID) ranges, whereas previously it could track only a single beginning and ending VID. VID ranges are stored as an array of beginning and ending (inclusive) integers.
|
||||
|
||||
#### Rack Types ([#12826](https://github.com/netbox-community/netbox/issues/12826))
|
||||
|
||||
A new rack type model has been introduced, which functions similar to the device type model. Users can now define a common make and model of rack, the attributes of which are automatically populated when creating a new rack of that type.
|
||||
|
||||
#### Plugins Catalog Integration ([#14731](https://github.com/netbox-community/netbox/issues/14731))
|
||||
|
||||
The NetBox UI now integrates directly with the canonical plugins catalog hosted by NetBox Labs. In addition to locally installed plugins, users can explore available plugins and check for newer releases.
|
||||
|
||||
#### User Notifications ([#15621](https://github.com/netbox-community/netbox/issues/15621))
|
||||
|
||||
NetBox now includes a user notification system. Users can subscribe to individual objects and be alerted to changes live within the web interface. Additionally, event rules can now trigger notifications to specific users and/or groups. Plugins can also employ this notification system for their own purposes.
|
||||
|
||||
### Enhancements
|
||||
|
||||
* [#7537](https://github.com/netbox-community/netbox/issues/7537) - Add a serial number field for virtual machines
|
||||
* [#8984](https://github.com/netbox-community/netbox/issues/8984) - Enable filtering of custom script output by log level
|
||||
* [#11969](https://github.com/netbox-community/netbox/issues/11969) - Support for tracking airflow on racks and module types
|
||||
* [#15156](https://github.com/netbox-community/netbox/issues/15156) - Add `display_url` field to all REST API serializers
|
||||
* [#16359](https://github.com/netbox-community/netbox/issues/16359) - Enable plugins to embed content in the top navigation bar
|
||||
* [#16580](https://github.com/netbox-community/netbox/issues/16580) - Enable individual views to enforce `LOGIN_REQUIRED` selectively (remove `AUTH_EXEMPT_PATHS`)
|
||||
* [#16776](https://github.com/netbox-community/netbox/issues/16776) - Added an `alerts()` method to `PluginTemplateExtension` for embedding important information about specific objects
|
||||
* [#16782](https://github.com/netbox-community/netbox/issues/16782) - Enable filtering of selection choices for object type custom fields
|
||||
* [#16866](https://github.com/netbox-community/netbox/issues/16866) - Introduced a mechanism for plugins to register custom event types (for use with user notifications)
|
||||
|
||||
### Plugins
|
||||
|
||||
@ -24,13 +50,31 @@
|
||||
### Other Changes
|
||||
|
||||
* [#14692](https://github.com/netbox-community/netbox/issues/14692) - Change atomic unit for virtual disks from 1GB to 1MB
|
||||
* [#14861](https://github.com/netbox-community/netbox/issues/14861) - The URL path for UI views concerning virtual disks has been standardized to `/virtualization/virtual-disks/`
|
||||
* [#15410](https://github.com/netbox-community/netbox/issues/15410) - Removed various deprecated filters
|
||||
* [#15908](https://github.com/netbox-community/netbox/issues/15908) - Indicate product edition in release data
|
||||
* [#16388](https://github.com/netbox-community/netbox/issues/16388) - Move all change logging resources from `extras` to `core`
|
||||
* [#16884](https://github.com/netbox-community/netbox/issues/16884) - Remove the ID column from the default table configuration for changelog records
|
||||
|
||||
### REST API Changes
|
||||
|
||||
* The `/api/extras/object-changes/` endpoint has moved to `/api/core/object-changes/`
|
||||
* Added the following endpoints:
|
||||
* `/api/circuits/circuit-groups/`
|
||||
* `/api/circuits/circuit-group-assignments/`
|
||||
* `/api/dcim/rack-types/`
|
||||
* circuits.Circuit
|
||||
* Added the `assignments` field, which lists all group assignments
|
||||
* dcim.ModuleType
|
||||
* Added the optional `airflow` choice field
|
||||
* dcim.Rack
|
||||
* Added the optional `rack_type` foreign key field
|
||||
* Added the optional `airflow` choice field
|
||||
* extras.CustomField
|
||||
* Added the `related_object_filter` JSON field for object and multi-object custom fields
|
||||
* ipam.VLANGroup
|
||||
* Removed the `min_vid` and `max_vid` fields
|
||||
* Added the `vid_ranges` field, and array of starting & ending VLAN IDs
|
||||
* virtualization.VirtualMachine
|
||||
* Added the optional `serial` field
|
||||
* wireless.WirelessLink
|
||||
|
@ -62,7 +62,7 @@ class CustomFieldSerializer(ValidatedModelSerializer):
|
||||
fields = [
|
||||
'id', 'url', 'display_url', 'display', 'object_types', 'type', 'related_object_type', 'data_type',
|
||||
'name', 'label', 'group_name', 'description', 'required', 'search_weight', 'filter_logic', 'ui_visible',
|
||||
'ui_editable', 'is_cloneable', 'default', 'weight', 'validation_minimum', 'validation_maximum',
|
||||
'ui_editable', 'is_cloneable', 'default', 'related_object_filter', 'weight', 'validation_minimum', 'validation_maximum',
|
||||
'validation_regex', 'validation_unique', 'choice_set', 'comments', 'created', 'last_updated',
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||
|
@ -67,7 +67,7 @@ class CustomFieldForm(forms.ModelForm):
|
||||
FieldSet(
|
||||
'search_weight', 'filter_logic', 'ui_visible', 'ui_editable', 'weight', 'is_cloneable', name=_('Behavior')
|
||||
),
|
||||
FieldSet('default', 'choice_set', name=_('Values')),
|
||||
FieldSet('default', 'choice_set', 'related_object_filter', name=_('Values')),
|
||||
FieldSet(
|
||||
'validation_minimum', 'validation_maximum', 'validation_regex', 'validation_unique', name=_('Validation')
|
||||
),
|
||||
|
@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0.7 on 2024-07-26 01:49
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0119_eventrule_event_types'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customfield',
|
||||
name='related_object_filter',
|
||||
field=models.JSONField(blank=True, null=True),
|
||||
),
|
||||
]
|
@ -154,6 +154,14 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
'Default value for the field (must be a JSON value). Encapsulate strings with double quotes (e.g. "Foo").'
|
||||
)
|
||||
)
|
||||
related_object_filter = models.JSONField(
|
||||
blank=True,
|
||||
null=True,
|
||||
help_text=_(
|
||||
'Filter the object selection choices using a query_params dict (must be a JSON value).'
|
||||
'Encapsulate strings with double quotes (e.g. "Foo").'
|
||||
)
|
||||
)
|
||||
weight = models.PositiveSmallIntegerField(
|
||||
default=100,
|
||||
verbose_name=_('display weight'),
|
||||
@ -373,6 +381,17 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
.format(type=self.get_type_display())
|
||||
})
|
||||
|
||||
# Related object filter can be set only for object-type fields, and must contain a dictionary mapping (if set)
|
||||
if self.related_object_filter is not None:
|
||||
if self.type not in (CustomFieldTypeChoices.TYPE_OBJECT, CustomFieldTypeChoices.TYPE_MULTIOBJECT):
|
||||
raise ValidationError({
|
||||
'related_object_filter': _("A related object filter can be defined only for object fields.")
|
||||
})
|
||||
if type(self.related_object_filter) is not dict:
|
||||
raise ValidationError({
|
||||
'related_object_filter': _("Filter must be defined as a dictionary mapping attributes to values.")
|
||||
})
|
||||
|
||||
def serialize(self, value):
|
||||
"""
|
||||
Prepare a value for storage as JSON data.
|
||||
@ -511,7 +530,8 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
field = field_class(
|
||||
queryset=model.objects.all(),
|
||||
required=required,
|
||||
initial=initial
|
||||
initial=initial,
|
||||
query_params=self.related_object_filter
|
||||
)
|
||||
|
||||
# Multiple objects
|
||||
@ -522,6 +542,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
queryset=model.objects.all(),
|
||||
required=required,
|
||||
initial=initial,
|
||||
query_params=self.related_object_filter
|
||||
)
|
||||
|
||||
# Text
|
||||
|
@ -23,7 +23,7 @@ from virtualization.models import Cluster, ClusterGroup, ClusterType
|
||||
class CustomFieldTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||
queryset = CustomField.objects.all()
|
||||
filterset = CustomFieldFilterSet
|
||||
ignore_fields = ('default',)
|
||||
ignore_fields = ('default', 'related_object_filter')
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
@ -52,6 +52,14 @@
|
||||
<th scope="row">{% trans "Default Value" %}</th>
|
||||
<td>{{ object.default }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Related object filter" %}</th>
|
||||
{% if object.related_object_filter %}
|
||||
<td><pre>{{ object.related_object_filter|json }}</pre></td>
|
||||
{% else %}
|
||||
<td>{{ ''|placeholder }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="card">
|
||||
|
Loading…
Reference in New Issue
Block a user