Add more information about custom object fields methods #7868

Closed
opened 2025-12-29 20:29:11 +01:00 by adam · 1 comment
Owner

Originally created by @kagarcia1618 on GitHub (Apr 6, 2023).

Change Type

Addition

Area

Features

Proposed Changes

When writing Netbox custom scripts that handles custom fields data, there are currently 3 available methods to access the data:

  1. .cf
  2. .custom_fields
  3. .custom_field_data

Current documentation does provide minor details about the usage information but did not provide any for the difference among these methods. These information for me is very helpful to avoid confusion when deciding which method to use when writing custom scripts. As @kkthxbye-code have answered in slack channel, below are the initial details for each of these methods:

  1. .cf is a read-only dictionary of deserialized custom field data.
  2. .custom_fields is a queryset of the custom fields assigned to the model.
  3. .custom_field_data is the raw JSON column containing the custom field data.
Originally created by @kagarcia1618 on GitHub (Apr 6, 2023). ### Change Type Addition ### Area Features ### Proposed Changes When writing Netbox custom scripts that handles custom fields data, there are currently 3 available methods to access the data: 1. `.cf` 2. `.custom_fields` 3. `.custom_field_data` Current documentation does provide minor details about the usage information but did not provide any for the difference among these methods. These information for me is very helpful to avoid confusion when deciding which method to use when writing custom scripts. As @kkthxbye-code have answered in [slack channel](https://netdev-community.slack.com/archives/C01P0FRSXRV/p1680702848892109?thread_ts=1680702399.108609&cid=C01P0FRSXRV), below are the initial details for each of these methods: 1. `.cf` is a read-only dictionary of deserialized custom field data. 2. `.custom_fields` is a queryset of the custom fields assigned to the model. 3. `.custom_field_data` is the raw JSON column containing the custom field data.
adam added the type: documentation label 2025-12-29 20:29:11 +01:00
adam closed this issue 2025-12-29 20:29:11 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 6, 2023):

As with most projects, you'll find the documentation for specific object attributes and methods in the codebase itself, in the form of comments and docstrings. This ensures the documentation is kept close to and synchronized with the code itself.

The cf and custom_fields properties are both thoroughly documented (including example usages) in the CustomFieldsMixin class where they are defined. The custom_field_data field also declared there is a standard field should not require any special explanation.

@jeremystretch commented on GitHub (Apr 6, 2023): As with most projects, you'll find the documentation for specific object attributes and methods in the codebase itself, in the form of comments and docstrings. This ensures the documentation is kept close to and synchronized with the code itself. The `cf` and `custom_fields` properties are both thoroughly documented (including example usages) in [the `CustomFieldsMixin` class](https://github.com/netbox-community/netbox/blob/f8d40ae8249d46884c185c87471af61d894dda35/netbox/netbox/models/features.py#L146) where they are defined. The `custom_field_data` field also declared there is a standard field should not require any special explanation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7868