20048 cleanup get_viewname URL resolution (#20050)
Some checks are pending
CI / build (20.x, 3.10) (push) Waiting to run
CI / build (20.x, 3.11) (push) Waiting to run
CI / build (20.x, 3.12) (push) Waiting to run

* #20048 add get_action_url utility function

* #20048 add get_action_url utility function

* #20048 add get_action_url utility function

* #20048 add get_action_url utility function

* #20048 add get_action_url utility function

* #20048 action_url template tag

* #20048 action_url template tag

* #20048 fix test

* #20048 review feedback

* #20048 fix tags
This commit is contained in:
Arthur Hanson
2025-08-11 05:38:19 -07:00
committed by GitHub
parent 1242ad68f7
commit a585bc044e
24 changed files with 220 additions and 115 deletions

View File

@@ -1,13 +1,13 @@
import inspect
from django.urls import NoReverseMatch, reverse
from django.urls import NoReverseMatch
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import extend_schema_field
from rest_framework import serializers
from core.models import ObjectType
from netbox.api.serializers import BaseModelSerializer
from utilities.views import get_viewname
from utilities.views import get_action_url
__all__ = (
'ObjectTypeSerializer',
@@ -34,11 +34,10 @@ class ObjectTypeSerializer(BaseModelSerializer):
def get_rest_api_endpoint(self, obj):
if not (model := obj.model_class()):
return
if viewname := get_viewname(model, action='list', rest_api=True):
try:
return reverse(viewname)
except NoReverseMatch:
return
try:
return get_action_url(model, action='list', rest_api=True)
except NoReverseMatch:
return
@extend_schema_field(OpenApiTypes.STR)
def get_description(self, obj):