Auto-increment CustomField #6941

Closed
opened 2025-12-29 19:47:02 +01:00 by adam · 1 comment
Owner

Originally created by @PieterL75 on GitHub (Sep 7, 2022).

NetBox version

v3.3.2

Feature type

New functionality

Proposed functionality

Create a custom field that auto-increments when a new object is created.
The custom field would hold a 'template', as in some cases a prefix is needed
Ex: DEV000000, DEV0000ALL, 000000SW where the 000000's would increment

Use case

Device in the racks are only labeled with global a unique number. (we don't use devicenames for compliance and shortlabels)
An auto-incrementing custom field would give us the abiility to create unique numbers for each created device

Database changes

No response

External dependencies

No response

Originally created by @PieterL75 on GitHub (Sep 7, 2022). ### NetBox version v3.3.2 ### Feature type New functionality ### Proposed functionality Create a custom field that auto-increments when a new object is created. The custom field would hold a 'template', as in some cases a prefix is needed Ex: DEV000000, DEV0000ALL, 000000SW where the 000000's would increment ### Use case Device in the racks are only labeled with global a unique number. (we don't use devicenames for compliance and shortlabels) An auto-incrementing custom field would give us the abiility to create unique numbers for each created device ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 19:47:02 +01:00
adam closed this issue 2025-12-29 19:47:02 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 7, 2022):

While I can appreciate the use case, I'm afraid this is just too much logic to pack into a custom field, which are intended to store static, prescribed values. What you're describing is akin to a database sequence, but actually more complex because you've employed a template to render the iterative portion of the value.

Instead, I'd suggest writing a simple plugin to hook into Django's post_save signal and employ whatever logic you'd like to automatically set these values. This approach is going to be much more flexible, as it allows for the consideration of other device parameters, such as role and status, when determining the value to apply.

@jeremystretch commented on GitHub (Sep 7, 2022): While I can appreciate the use case, I'm afraid this is just too much logic to pack into a custom field, which are intended to store static, prescribed values. What you're describing is akin to a database sequence, but actually more complex because you've employed a template to render the iterative portion of the value. Instead, I'd suggest writing a simple plugin to hook into Django's [post_save](https://docs.djangoproject.com/en/4.1/ref/signals/#django.db.models.signals.post_save) signal and employ whatever logic you'd like to automatically set these values. This approach is going to be _much_ more flexible, as it allows for the consideration of other device parameters, such as role and status, when determining the value to apply.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6941