-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v3.4.6
Feature type
Data model extension
Proposed functionality
The JobResult model current has a ForeignKey field to ContentType, which enables associating an instance with a particular type of NetBox model. It also has a name field to indicate the object's name, however this is not a concrete relationship in the database. This is due to the limitation of scripts and reports not being tracked as database objects.
This FR proposes the additional of an object ID field to complement the object type field, which will enable GenericForeignKey assignments for JobResults. This is possible thanks to the implementation of #11890, which introduces "real" database models representing reports and scripts.
The following changes are proposed for the JobResult model:
- Rename
obj_typetoobject_typefor consistency with other NetBox models using GFK. - Add an
object_idinteger field. - Add a GenericForeignKey field leveraging both of the above. Object types will be limited to those models inheriting from
JobResultsMixin.
We'll keep the name field as an optional field: It can be used to differentiate among jobs pertaining to the same object. For example, we can expect a ScriptModule containing multiple scripts to have separate jobs for each script.
Use case
Introducing a database relationship between a job and its assigned object enables more robust and efficient correlation and management of jobs. For example, we'll be able to pull all jobs pertaining to a specific script via it's module:
ScriptModule.jobs.filter(name='myscript1')
Database changes
No response
External dependencies
No response