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

fix(generic): allow to overwrite APIViewsets #1300

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apis_core/generic/generators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.contenttypes.models import ContentType
from django.urls import resolve, reverse
from drf_spectacular.generators import EndpointEnumerator, SchemaGenerator
from .helpers import first_member_match, module_paths

from apis_core.generic.abc import GenericModel

Expand Down Expand Up @@ -34,9 +35,15 @@ def _generate_content_type_endpoint(
self, content_type: ContentType, method: str = "list"
):
"""Create a endpoint tuple, usable by the SchemaGenerator of DRF spectacular"""
api_viewsets = module_paths(
content_type.model_class(), path="api_views", suffix="APIViewSet"
)
cls = first_member_match(api_viewsets)
path = reverse("apis_core:generic:genericmodelapi-list", args=[content_type])
cls = resolve(path).func.cls

if cls is None:
cls = resolve(path).func.cls
else:
pass
if method == "detail":
path += "{id}/"
regex = path
Expand Down
Loading