Skip to content

Propagate 'default' from model_field to serializer field #8002

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

john-parton
Copy link
Contributor

@john-parton john-parton commented May 21, 2021

Description

This is an attempt to fix #7469

It's actually really simple. ModelSerializer.build_standard_field looks for the default key in the dictionary returned by get_field_kwargs, but get_field_kwargs never returns a dictionary with that key.

Edit

I was personally motivated to fix this because I wanted the default value to appear when you do an OPTIONS query. That's incredibly tedious without this fix. More info here: #8003

@SchrodingersGat
Copy link

SchrodingersGat commented Jun 21, 2021

@john-parton I have been trawling through the DRF documentation trying to work out how to use the default parameter for a django model by "default" for the fields in a ModelSerializer.

It appears that this is not actually possible (until this PR is merged)?

I would have assumed that this was a natural and reasonable feature to expect! +1 to getting this feature merged it this is not already the case.

@benesch
Copy link
Contributor

benesch commented Aug 13, 2021

Thanks, @john-parton, I just really wanted this too! There were are a few test failures here that I'm going to clean up and resubmit as a new PR.

@benesch
Copy link
Contributor

benesch commented Aug 13, 2021

Submitted as #8130.

@john-parton
Copy link
Contributor Author

Superseded by #8130

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ModelSerializer generate ChoicesField will discard default parameter
3 participants