tomchristie/django-rest-framework — pull request #2286 by spectras (2014-12-17 04:27:45+00:00)
Title: Compatibility / feature request : replacement for get_default_fields()?

Hello,

I am using [django-hvad](https://github.com/KristianOellegaard/django-hvad/) in my projects and used to have some glue code to make it work with restframework version 2. I used to be able to do this:
```python
class TranslatableModelSerializer(ModelSerializer):
# other stuff
def get_default_fields(self):
fields = super(TranslatableModelMixin, self).get_default_fields()
fields.update(self._get_translated_fields())
return fields
````

I am now in the process of switching to restframework v3. Unfortunately, it seems this method disappeared. The new way of getting serializer fields is a huge monolithic method, which is completely impossible to customize, as far as I see it.

I tried overriding `_get_default_field_names`, but it fails at a later point, because additional field names are not known to the new `get_fields` method, causing it to raise an `ImproperlyConfigured('Field name `%s` is not valid for model `%s`.')` exception.

What would my options be? So far I can only see those:
- Override the whole `get_fields` method and copy paste the whole thing just to add one additional case in the if…else list.
- Patch the `model_info` argument in `_get_default_field_names` (it is passed by reference). That feels both hackish and very fragile.
- Reimplement part of `get_fields` related to my model in `__init__` to append to `self.fields`

What I would love to see is a that the `get_fields` method from `ModelSerializer` gives a chance for a derived class to provide info (namely, `field_cls` and `kwargs`) for custom fields before raising. I can make a PR if that feels appropriate.