Skip to content

Commit

Permalink
fix: let use a default value for foreignkey model field
Browse files Browse the repository at this point in the history
  • Loading branch information
freddez committed Dec 17, 2022
1 parent 7bfcfb1 commit f6929d0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,14 @@ def _get_serializer_field_meta(self, field, direction):
if not field.read_only:
meta['minLength'] = 1
if field.default is not None and field.default != empty and not callable(field.default):
if isinstance(field, (serializers.ModelField, serializers.SerializerMethodField)):
if isinstance(
field,
(
serializers.ModelField,
serializers.SerializerMethodField,
serializers.PrimaryKeyRelatedField,
),
):
# Skip coercion for lack of a better solution. ModelField.to_representation()
# and SerializerMethodField.to_representation() are special in that they require
# a model instance or object (which we don't have) instead of a plain value.
Expand Down

0 comments on commit f6929d0

Please sign in to comment.