-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
allow default boolean values to be honoured #1248
Conversation
@@ -1720,3 +1720,36 @@ def test_missing_fields(self): | |||
'b_renamed': None, | |||
} | |||
) | |||
class DefaultTrueBooleanModel(models.Model): | |||
cat = models.BooleanField(default=True) | |||
dog = models.BooleanField(default=True) |
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.
Why not test both default=True
and default=False
?
Whilst following the recommendations from Ian-Foote (thanks by the way) I found another small bug - if a default was set but the field was not specified when the serialiser was initialised then it would return as None. This is seen with this:
|
Kick me on this thread if I've not reviewed this in the next few days :) |
Just a few quick things that are a problem with this pull request. When serializers are initialized, the first argument is the instance. So in all of your tests, the data is not being passed into the serializer, so none of them are valid (you can test this by calling The last test ( With all of that in mind, I created a new pull request (#1291) which fixes the issue in a different way. |
Closing in favor of #1291. Thanks for the input! |
Hi Kevin, Thank you for taking the time to explain everything - it has been a great help. |
In response to request #1101 "Default Boolean value always becomes False even default=True is specified in model class."
This allows a default to be used when the field is not specified in the request.