Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix schema generation for PrimaryKeyRelatedField#5764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
carltongibson merged 1 commit intoencode:masterfromjlaine:foreign-key-schema
Feb 1, 2018
Merged

Fix schema generation for PrimaryKeyRelatedField#5764

carltongibson merged 1 commit intoencode:masterfromjlaine:foreign-key-schema
Feb 1, 2018

Conversation

@jlaine
Copy link
Contributor

@jlainejlaine commentedJan 23, 2018
edited
Loading

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 inthe schema, which works well for StringRelatedField, SlugRelatedField orHyperlinkedRelatedField.Handle the common case of a PrimaryKeyRelatedField pointing to anAutoField.
@jlainejlaine changed the titleDetect AutoField foreign keys when generating schemaFix schema generation for PrimaryKeyRelatedFieldJan 23, 2018
@jlaine
Copy link
ContributorAuthor

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 notrequired 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.

@carltongibson
Copy link
Collaborator

@jlaine Just on your related note: my immediate thought is that ifread_only_fields is misbehaving for you is to explicitly declare the field.read_only_fields is a short-cut, it's task is to cover the common-case. The canonical approach is always to explicitly declare the field.

If that doesn't suit then put together a proper description and open a new ticket and we'll have a look.

Copy link
Collaborator

@carltongibsoncarltongibson left a 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!

@carltongibsoncarltongibson added this to the3.8 Release milestoneFeb 1, 2018
@carltongibsoncarltongibson merged commit27f32fa intoencode:masterFeb 1, 2018
@jlaine
Copy link
ContributorAuthor

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:

assertnot (self.querysetisnotNoneandkwargs.get('read_only',None)), (

@carltongibson
Copy link
Collaborator

OK. Open a new ticket and we’ll think it through

@jlainejlaine deleted the foreign-key-schema branchApril 9, 2018 06:43
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull requestNov 17, 2020
By default all subclasses of RelatedField are output as string fields inthe schema, which works well for StringRelatedField, SlugRelatedField orHyperlinkedRelatedField.Handle the common case of a PrimaryKeyRelatedField pointing to anAutoField.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@carltongibsoncarltongibsoncarltongibson approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.8.0 Release

Development

Successfully merging this pull request may close these issues.

2 participants

@jlaine@carltongibson

[8]ページ先頭

©2009-2025 Movatter.jp