sloria/marshmallow — pull request #4 by elbaschid (2013-11-20 04:52:13+00:00)
Title: Pass attribute name through to method and function field callables

As the branch name says, this is a suggestion. I've been looking into a use case for a serializer that has several ``Method`` fields that serialise different attributes but basically do the same thing. Unfortunately, within the callables used by the ``Method`` and ``Function`` field, I don't know anything about the attribute name of the field. It would be nice to have that, especially since the ``key`` value is available in the ``to_output`` methods of the fields and just needs to be passed in. A simple example would be something like this:
```
class CustomSerializer(Serializer):
first_name = fields.Method('get_lowercase_attribute')
last_name = fields.Method('get_lowercase_attribute')

def get_lowercase_attribute(self, key, obj):
return getattr(obj, key)
```

I've added the argument to both fields in this PR. This will cause problems for existing code that uses these fields so I would be good to get your input on whether you want backwards compatibility or not. What are your thoughts?