Dynamic class typing

This commit is contained in:
Oliver Walters 2026-07-02 12:18:46 +00:00
parent 0943733328
commit 5061e6b935
1 changed files with 9 additions and 3 deletions

View File

@ -963,9 +963,6 @@ class DuplicateOptionsSerializer(serializers.Serializer):
Arguments:
queryset: Queryset used for the `original` PrimaryKeyRelatedField.
copy_parameters: Include a field to specify whether to copy parameters from the original instance (default True).
copy_lines: Include a field to specify whether to copy line items from the original instance (default False).
copy_extra_lines: Include a field to specify whether to copy extra line items from the original instance (default False).
copy_fields: Optional list of dicts, each describing one boolean copy toggle.
Keys:
name: (str, required)
@ -1002,6 +999,15 @@ class DuplicateOptionsSerializer(serializers.Serializer):
super().__init__(*args, **kwargs)
# Re-class the instance with a model-specific subclass,
# so that each model generates a unique schema component name
if self.__class__ is DuplicateOptionsSerializer:
self.__class__ = type(
f'{queryset.model.__name__}DuplicateOptionsSerializer',
(DuplicateOptionsSerializer,),
{},
)
self.fields['original'] = serializers.PrimaryKeyRelatedField(
queryset=queryset,
required=True,