dabapps / django-rest-framework-serialization-spec

DEPRECATED, see https://github.com/dabapps/django-readers instead
MIT License
11 stars 0 forks source link

Allow serialization_spec to be built at runtime #37

Closed pmg103 closed 4 years ago

pmg103 commented 4 years ago

As an alternative to

    serialization_spec = [
        'sessions'
    ]

It ought to be possible to provide a method get_serialization_spec(self), following the pattern from DRF, so that the spec can depend on values at runtime (most likely the request user):

    def get_serialization_spec(self)
        return [
            {'sessions': Filtered(Q(created_by=self.request.user), [
               'id'
            ]}
        ]

Note that for this to work in SerializationSpecPlugins, request_user would have to be assigned before calling get_serialization_spec()