mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 13:30:12 +03:00
added *args **kwargs to field_to_native
only SerializerMethodField's functionality changes; it now passes *args, **kwargs to the method in addition to the object. we add *args, **kwargs to the rest of the fields so when people look at the code they know if can be passed additional args.
This commit is contained in:
parent
b4f0fab043
commit
a8711f6ab2
|
@ -180,7 +180,7 @@ class Field(object):
|
||||||
"""
|
"""
|
||||||
return
|
return
|
||||||
|
|
||||||
def field_to_native(self, obj, field_name):
|
def field_to_native(self, obj, field_name, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Given and object and a field name, returns the value that should be
|
Given and object and a field name, returns the value that should be
|
||||||
serialized for that field.
|
serialized for that field.
|
||||||
|
@ -328,10 +328,10 @@ class WritableField(Field):
|
||||||
if errors:
|
if errors:
|
||||||
raise ValidationError(errors)
|
raise ValidationError(errors)
|
||||||
|
|
||||||
def field_to_native(self, obj, field_name):
|
def field_to_native(self, obj, field_name, *args, **kwargs):
|
||||||
if self.write_only:
|
if self.write_only:
|
||||||
return None
|
return None
|
||||||
return super(WritableField, self).field_to_native(obj, field_name)
|
return super(WritableField, self).field_to_native(obj, field_name, *args, **kwargs)
|
||||||
|
|
||||||
def field_from_native(self, data, files, field_name, into):
|
def field_from_native(self, data, files, field_name, into):
|
||||||
"""
|
"""
|
||||||
|
@ -413,7 +413,7 @@ class ModelField(WritableField):
|
||||||
else:
|
else:
|
||||||
return self.model_field.to_python(value)
|
return self.model_field.to_python(value)
|
||||||
|
|
||||||
def field_to_native(self, obj, field_name):
|
def field_to_native(self, obj, field_name, *args, **kwargs):
|
||||||
value = self.model_field._get_val_from_obj(obj)
|
value = self.model_field._get_val_from_obj(obj)
|
||||||
if is_protected_type(value):
|
if is_protected_type(value):
|
||||||
return value
|
return value
|
||||||
|
@ -1022,6 +1022,6 @@ class SerializerMethodField(Field):
|
||||||
self.method_name = method_name
|
self.method_name = method_name
|
||||||
super(SerializerMethodField, self).__init__()
|
super(SerializerMethodField, self).__init__()
|
||||||
|
|
||||||
def field_to_native(self, obj, field_name):
|
def field_to_native(self, obj, field_name, *args, **kwargs):
|
||||||
value = getattr(self.parent, self.method_name)(obj)
|
value = getattr(self.parent, self.method_name)(obj, *args, **kwargs)
|
||||||
return self.to_native(value)
|
return self.to_native(value)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user