mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Set allow_none = True for CharFields with null=True
				
					
				
			This commit is contained in:
		
							parent
							
								
									6e622d644c
								
							
						
					
					
						commit
						e1bbe9d514
					
				| 
						 | 
					@ -821,10 +821,15 @@ class ModelSerializer(Serializer):
 | 
				
			||||||
                kwargs.update({attribute: getattr(model_field, attribute)})
 | 
					                kwargs.update({attribute: getattr(model_field, attribute)})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            return self.field_mapping[model_field.__class__](**kwargs)
 | 
					            field_class = self.field_mapping[model_field.__class__]
 | 
				
			||||||
        except KeyError:
 | 
					        except KeyError:
 | 
				
			||||||
            return ModelField(model_field=model_field, **kwargs)
 | 
					            return ModelField(model_field=model_field, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if issubclass(field_class, CharField) and model_field.null:
 | 
				
			||||||
 | 
					            kwargs['allow_none'] = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return field_class(**kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_validation_exclusions(self):
 | 
					    def get_validation_exclusions(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Return a list of field names to exclude from model validation.
 | 
					        Return a list of field names to exclude from model validation.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user