New third party package: Serializer extensions

25 views
Skip to first unread message

Ian Clark

unread,
Jan 3, 2017, 6:08:26 PM1/3/17
to Django REST framework
In what seems like classic multiple discovery to - I've just created a third party package based a solution used at my company to reduce the need to create multiple, very similar, serializers. We found that as our API grew, we ended up with very slightly different use cases for individual views, and that, along with our heavily normalized modelling, resulted in massive repetition.

Hopefully the Serializer Extensions package should clear that up somewhat. It provides an "expandable_fields" API which allows child serializers to be optionally included, depending on the view/request's context. It supports nested expansion, as well as the ability to blacklist/whitelist fields as required. It also includes a HashIdField to promote the use of HashIds vs publicly exposing internal primary keys.

I've also started some work to try to automatically optimize the queries (through using select/prefetches as required) based on what is expanded, and will be looking through some of the closed issues on GH where you've promoted the use of third-party packages to get an idea of how it can be best applied (i.e. to avoid using prefetches when using a paginator).

Thanks for all your work on DRF Tom, and I found the cookiecutter template really useful (as this is my first dive into Python packages). It's a little out of date though, and perhaps could do with being updated / updating the documentation to mention that dependencies etc. should be updated to match current-2 for Django and Rest Framework. I'd be happy to look into that if you like?

I'll submit a PR to include a link to Serializer Extensions from the DRF docs, and would love to add it to the Django Packages grid if you're happy?

Thanks,

Ian
Reply all
Reply to author
Forward
0 new messages