Skip to content

Define a get_absolute_url() method on NetBoxModel #16546

Closed
@jeremystretch

Description

@jeremystretch

Proposed Changes

Add a get_absolute_url() method on NetBoxModel to dynamically return the appropriate URL based on the model's app_label and model_name Meta attributes:

    def get_absolute_url(self):
        return reverse(f'{self._meta.app_label}:{model_name}', args=[self.pk])

Justification

The vast majority of models in NetBox declare this method explicitly. Moving it to NetBoxModel allows us to remove boilerplate code while still permitting customization on individual models.

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: housekeepingChanges to the application which do not directly impact the end user

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions