mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-10-30 23:47:53 +03:00 
			
		
		
		
	A model's field is required if is null or blank
This commit is contained in:
		
							parent
							
								
									34776da924
								
							
						
					
					
						commit
						de5cc8de42
					
				|  | @ -705,15 +705,14 @@ class ModelSerializer(Serializer): | |||
|         Creates a default instance of a basic non-relational field. | ||||
|         """ | ||||
|         kwargs = {} | ||||
|         has_default = model_field.has_default() | ||||
| 
 | ||||
|         if model_field.null or model_field.blank or has_default: | ||||
|         if model_field.null or model_field.blank: | ||||
|             kwargs['required'] = False | ||||
| 
 | ||||
|         if isinstance(model_field, models.AutoField) or not model_field.editable: | ||||
|             kwargs['read_only'] = True | ||||
| 
 | ||||
|         if has_default: | ||||
|         if model_field.has_default(): | ||||
|             kwargs['default'] = model_field.get_default() | ||||
| 
 | ||||
|         if issubclass(model_field.__class__, models.TextField): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user