From 1cc79a34e0fcd7d52d9c102ed672938f85815617 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Tue, 7 Jan 2020 19:33:35 -0500 Subject: [PATCH] Remove special case for mapping `NullBooleanField` In newer versions of Django, the `NullBooleanField` is handled the same way as a `BooleanField(null=True)`. Given that we also support that combination, and that our own `NullBooleanField` behaves in the same manner, it makes sense to remove the special casing that exists for it. --- rest_framework/serializers.py | 2 +- rest_framework/utils/field_mapping.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 8c2486bea..bfd682630 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -868,7 +868,7 @@ class ModelSerializer(Serializer): models.FloatField: FloatField, models.ImageField: ImageField, models.IntegerField: IntegerField, - models.NullBooleanField: NullBooleanField, + models.NullBooleanField: BooleanField, models.PositiveIntegerField: IntegerField, models.PositiveSmallIntegerField: IntegerField, models.SlugField: SlugField, diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py index a25880d0f..646bcd493 100644 --- a/rest_framework/utils/field_mapping.py +++ b/rest_framework/utils/field_mapping.py @@ -104,9 +104,6 @@ def get_field_kwargs(field_name, model_field): if model_field.has_default() or model_field.blank or model_field.null: kwargs['required'] = False - if model_field.null and not isinstance(model_field, models.NullBooleanField): - kwargs['allow_null'] = True - if model_field.blank and (isinstance(model_field, (models.CharField, models.TextField))): kwargs['allow_blank'] = True