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 depend on runtime values #39

Closed pmg103 closed 4 years ago

pmg103 commented 4 years ago

If the serialization_spec is to depend on a runtime value (such as self.request.user) then allow it to be specified in a get_serialization_spec() method.

Addresses https://github.com/dabapps/django-rest-framework-serialization-spec/issues/37

j4mie commented 4 years ago

Looks good. I idly wonder whether this sort of thing is so common (ie you almost always want a list of things that are visible to the current user) then maybe there'd be a nicer way to do this declaritively: created_by=LazyRequestUser() or CurrentUserFilter(field="created_by") or something. But I have no idea how this would be implemented and it sounds complicated.

pmg103 commented 4 years ago

Right yeah you could just have a placeholder for RequestUser that would get handled specially in the logic. Could take that approach instead. Pros and cons I guess. I went with something that felt very DRF-esque.