-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Fix schema generation for PrimaryKeyRelatedField #5764
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.