Fix schema generation for PrimaryKeyRelatedField#5764
Conversation
By default all subclasses of RelatedField are output as string fields in the schema, which works well for StringRelatedField, SlugRelatedField or HyperlinkedRelatedField. Handle the common case of a PrimaryKeyRelatedField pointing to an AutoField.
|
On a related note, I noticed that including a foreign key field in "read_only_fields" nukes the "queryset" kwarg: I understand why having this attribute is not required for a read-only field, but what is the harm in keeping it? Nuking this attribute removes the link to the foreign model and makes it much harder to generate a schema for the output of a serializer. |
|
@jlaine Just on your related note: my immediate thought is that if If that doesn't suit then put together a proper description and open a new ticket and we'll have a look. |
carltongibson
left a comment
There was a problem hiding this comment.
Yep. This looks good. Thanks!
|
Thanks for merging this! Concerning the read_only_fields, explicitly declaring the field doesn't help : there is code to prevent you from providing a queryset on a field you declare as read_only. Not sure what the rationale is: |
|
OK. Open a new ticket and we’ll think it through |
By default all subclasses of RelatedField are output as string fields in the schema, which works well for StringRelatedField, SlugRelatedField or HyperlinkedRelatedField. Handle the common case of a PrimaryKeyRelatedField pointing to an AutoField.
By default all subclasses of RelatedField are output as string fields in
the schema, which works well for StringRelatedField, SlugRelatedField or
HyperlinkedRelatedField.
Handle the common case of a PrimaryKeyRelatedField pointing to an
AutoField.