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

Fixes 18555: Fix model URL generator for plugins #18607

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alehaa
Copy link
Contributor

@alehaa alehaa commented Feb 8, 2025

Fixes: #18555

The default get_absolute_url() implementation can now return the URL for plugins.

Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues with the fix itself, but I'd like to see if we can find a less disruptive solution for testing.


class DummyModel(models.Model):

class DummyModel(NetBoxModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has implications beyond the scope of the bug report. Most importantly, we specifically want to test support for basic Django models introduced in plugins.

Rather than modify the core test model, it might be possible to use Django's isolate_apps utility to create a NetBoxModel subclass temporarily, specifically to test the functionality of its get_absolute_url() method. Something like this could work:

class ModelTest(TestCase):

    @isolate_apps('dummy_plugin')
    def test_get_absolute_url(self):
        class TestModel(NetBoxModel):
            pass

        model = TestModel()
        model.pk = 123
        self.assertEqual(TestModel.get_absolute_url(), f'/plugins/dummy-plugin/models/{m.pk}/')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Plugins not covered by get_absolute_url()
2 participants