NullBooleanField should use forms.NullBooleanField just like django. And BooleanField should support default=True
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Inizia con la riproduzione booleana minima in boolean/models.py e con il relativo TestBooleanSerializer, quindi esegui i comandi di migrazione e del server Django elencati per osservare il comportamento di BooleanField e NullBooleanField. Il lavoro è completato quando il comportamento del serializer corrisponde alla gestione prevista dei campi dei form Django e conserva un default=True esplicito durante l'input di un form HTML, con la copertura dei casi segnalati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Checklist
- I have verified that that issue exists against the
masterbranch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- This is not a usage question. (Those should be directed to the discussion group instead.)
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
run shell command
django-admin startproject forboolean
cd forboolean
django-admin startapp boolean
boolean/models.py
from django.db import models
from rest_framework import serializers
from rest_framework import viewsets
from rest_framework import permissions
''' not good example but make it small '''
class TestBoolean(models.Model):
acknowledged = models.BooleanField(null=True, blank=True)
autoRenewing = models.NullBooleanField()
class TestBooleanSerializer(serializers.ModelSerializer):
class Meta:
model = TestBoolean
fields = '__all__'
class TestBooleanViewSet(viewsets.ModelViewSet):
queryset = TestBoolean.objects.all()
serializer_class = TestBooleanSerializer
permission_classes = [permissions.AllowAny]
add app in forboolean/settings.py
'rest_framework',
'boolean',
modify forboolean/urls.py
from django.urls import path, include
from boolean.models import TestBooleanViewSet
from rest_framework import routers
router = routers.DefaultRouter()
router.register(r'boolean', TestBooleanViewSet)
urlpatterns = [
path('', include(router.urls)),
]
run shell command
./manage.py makemigrations boolean
./manage migrate
./manage runserver
stdout
......
WARNINGS:
boolean.TestBoolean.autoRenewing: (fields.W903) NullBooleanField is deprecated. Support for it (except in historical migrations) will be removed in Django 4.0.
HINT: Use BooleanField(null=True) instead.
......
Expected behavior
django doc https://docs.djangoproject.com/en/3.1/ref/models/fields/#booleanfield
class BooleanField(**options)¶
A true/false field.
The default form widget for this field is CheckboxInput, or NullBooleanSelect if null=True.
The default value of BooleanField is None when Field.default isn’t defined.

Actual behavior
When using HTML encoded form input be aware that omitting a value will always be treated as setting a field to False, even if it has a default=True option specified. This is because HTML checkbox inputs represent the unchecked state by omitting the value, so REST framework treats omission as if it is an empty checkbox input.
Note that Django 2.1 removed the blank kwarg from models.BooleanField. Prior to Django 2.1 models.BooleanField fields were always blank=True. Thus since Django 2.1 default serializers.BooleanField instances will be generated without the required kwarg (i.e. equivalent to required=True) whereas with previous versions of Django, default BooleanField instances will be generated with a required=False option. If you want to control this behaviour manually, explicitly declare the BooleanField on the serializer class, or use the extra_kwargs option to set the required flag.


- Lingua principale
- Python
- Stelle
- 30.2k
- Fork
- 7.1k
- Merge medio
- 1g 20h
- PR unite (30g)
- 19
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di encode/django-rest-framework
-
Documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
encode/django-rest-framework#3460 · 37 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
a viewset's action list gets "head" added to it, but only after being called at least onceForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
encode/django-rest-framework#9747 · 8 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Performance issue: N+1 queries and slow validation when using many=True with serializers containing relational fieldsForse già presa @adelkhayata76 l’ha presa 120 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
encode/django-rest-framework#9607 · 14 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
BookListSerializer example for create case is still flawedForse già presa @AyushDharDubey l’ha presa 644 giorni fa. Apertastale
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
encode/django-rest-framework#9469 · 4 commenti · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Not possible to override serializer_field_mappings with a field that has choices (for example a from ChoiceField derived field)Forse già presa @G-Glitch404 l’ha presa 8 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
encode/django-rest-framework#9179 · 9 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di encode/django-rest-framework
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
huggingface/sentence-transformers#4186 ·
I maintainer di solito rispondono entro 5 giorni
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
QuantEcon/QuantEcon.py#988 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
fabriziosalmi/certmate#1247 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
sujithputta02/Esapay#13 ·