Skip to content

Commit

Permalink
Add a comment, related to inline_serializer usage with `drf-spectac…
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoRado committed Aug 12, 2023
1 parent 0427252 commit 5df008f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from rest_framework import serializers

from styleguide_example.common.utils import inline_serializer, make_mock_object
from styleguide_example.api.utils import inline_serializer
from styleguide_example.common.utils import make_mock_object


class InlineSerializerTests(unittest.TestCase):
Expand Down
4 changes: 4 additions & 0 deletions styleguide_example/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def create_serializer_class(name, fields):


def inline_serializer(*, fields, data=None, **kwargs):
# Important note if you are using `drf-spectacular`
# Please refer to the following issue:
# https://github.com/HackSoftware/Django-Styleguide/issues/105#issuecomment-1669468898
# Since you might need to use unique names (uuids) for each inline serializer
serializer_class = create_serializer_class(name="inline_serializer", fields=fields)

if data is not None:
Expand Down
14 changes: 0 additions & 14 deletions styleguide_example/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.http import Http404
from django.shortcuts import get_object_or_404
from rest_framework import serializers


def make_mock_object(**kwargs):
Expand All @@ -20,19 +19,6 @@ def get_object(model_or_queryset, **kwargs):
return None


def create_serializer_class(name, fields):
return type(name, (serializers.Serializer,), fields)


def inline_serializer(*, fields, data=None, **kwargs):
serializer_class = create_serializer_class(name="", fields=fields)

if data is not None:
return serializer_class(data=data, **kwargs)

return serializer_class(**kwargs)


def assert_settings(required_settings, error_message_prefix=""):
"""
Checks if each item from `required_settings` is present in Django settings
Expand Down

0 comments on commit 5df008f

Please sign in to comment.