mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Only HTML forms should have implicit default False for boolean fields
This commit is contained in:
		
							parent
							
								
									34d65119fc
								
							
						
					
					
						commit
						28ff6fb1ec
					
				| 
						 | 
					@ -16,6 +16,7 @@ from django.core import validators
 | 
				
			||||||
from django.core.exceptions import ValidationError
 | 
					from django.core.exceptions import ValidationError
 | 
				
			||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from django.db.models.fields import BLANK_CHOICE_DASH
 | 
					from django.db.models.fields import BLANK_CHOICE_DASH
 | 
				
			||||||
 | 
					from django.http import QueryDict
 | 
				
			||||||
from django.forms import widgets
 | 
					from django.forms import widgets
 | 
				
			||||||
from django.utils.encoding import is_protected_type
 | 
					from django.utils.encoding import is_protected_type
 | 
				
			||||||
from django.utils.translation import ugettext_lazy as _
 | 
					from django.utils.translation import ugettext_lazy as _
 | 
				
			||||||
| 
						 | 
					@ -399,10 +400,15 @@ class BooleanField(WritableField):
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    empty = False
 | 
					    empty = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Note: we set default to `False` in order to fill in missing value not
 | 
					    def field_from_native(self, data, files, field_name, into):
 | 
				
			||||||
    # supplied by html form.  TODO: Fix so that only html form input gets
 | 
					        # HTML checkboxes do not explicitly represent unchecked as `False`
 | 
				
			||||||
    # this behavior.
 | 
					        # we deal with that here...
 | 
				
			||||||
    default = False
 | 
					        if isinstance(data, QueryDict):
 | 
				
			||||||
 | 
					            self.default = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return super(BooleanField, self).field_from_native(
 | 
				
			||||||
 | 
					            data, files, field_name, into
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def from_native(self, value):
 | 
					    def from_native(self, value):
 | 
				
			||||||
        if value in ('true', 't', 'True', '1'):
 | 
					        if value in ('true', 't', 'True', '1'):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user