Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a get_absolute_url() method on NetBoxModel #16546

Closed
jeremystretch opened this issue Jun 13, 2024 · 2 comments
Closed

Define a get_absolute_url() method on NetBoxModel #16546

jeremystretch opened this issue Jun 13, 2024 · 2 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Milestone

Comments

@jeremystretch
Copy link
Member

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.

@jeremystretch jeremystretch added type: housekeeping Changes to the application which do not directly impact the end user status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Jun 13, 2024
@sleepinggenius2
Copy link
Contributor

Would the proposed solution work for plugin models that inherit from NetBoxModel too? It would be nice to do away with the boilerplate there as well.

@jeremystretch jeremystretch added this to the v4.2 milestone Aug 15, 2024
@jeremystretch jeremystretch added status: backlog Awaiting selection for work and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Aug 15, 2024
@arthanson arthanson self-assigned this Oct 7, 2024
@arthanson arthanson added status: accepted This issue has been accepted for implementation and removed status: backlog Awaiting selection for work labels Oct 7, 2024
@jeremystretch
Copy link
Member Author

A get_absolute_url() method has been added to the NetBoxFeatureSet mixin, which is used by NetBoxModel, OrganizationalModel, and NestedGroupModel.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

No branches or pull requests

3 participants