mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-24 14:17:49 -06:00
20048 cleanup get_viewname URL resolution (#20050)
* #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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user