mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-10-30 15:37:50 +03:00 
			
		
		
		
	Simplify serialization slightly
This commit is contained in:
		
							parent
							
								
									8be4496586
								
							
						
					
					
						commit
						6090144608
					
				|  | @ -202,12 +202,15 @@ class Field(object): | ||||||
|             return self.default_empty_html if (ret == '') else ret |             return self.default_empty_html if (ret == '') else ret | ||||||
|         return dictionary.get(self.field_name, empty) |         return dictionary.get(self.field_name, empty) | ||||||
| 
 | 
 | ||||||
|     def get_attribute(self, instance): |     def get_field_representation(self, instance): | ||||||
|         """ |         """ | ||||||
|         Given the *outgoing* object instance, return the value for this field |         Given the outgoing object instance, return the primative value | ||||||
|         that should be returned as a primative value. |         that should be used for this field. | ||||||
|         """ |         """ | ||||||
|         return get_attribute(instance, self.source_attrs) |         attribute = get_attribute(instance, self.source_attrs) | ||||||
|  |         if attribute is None: | ||||||
|  |             return None | ||||||
|  |         return self.to_representation(attribute) | ||||||
| 
 | 
 | ||||||
|     def get_default(self): |     def get_default(self): | ||||||
|         """ |         """ | ||||||
|  |  | ||||||
|  | @ -268,8 +268,7 @@ class Serializer(BaseSerializer): | ||||||
|         fields = [field for field in self.fields.values() if not field.write_only] |         fields = [field for field in self.fields.values() if not field.write_only] | ||||||
| 
 | 
 | ||||||
|         for field in fields: |         for field in fields: | ||||||
|             native_value = field.get_attribute(instance) |             ret[field.field_name] = field.get_field_representation(instance) | ||||||
|             ret[field.field_name] = field.to_representation(native_value) |  | ||||||
| 
 | 
 | ||||||
|         return ret |         return ret | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user