You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My serializer should calculate some values which depend on the user's account.
I subclassed ModelSerializer (from wq), and can't find a way to reliably determine the request in the constructor (to prepare information for to_representation method to use for every serialized instance).
According to https://stackoverflow.com/a/34617511/1762343, the request should be in self.context dict, but I can only (sometimes) find 'router': <wq.db.rest.routers.ModelRouter> there.
The text was updated successfully, but these errors were encountered:
The router initializes the serializers at startup to generate the configuration object. So, there isn't any request in the context at that time. But once you get to actually rendering and parsing records the request object should be there. So, you just need to have a check or a fallback when dealing with code that relies on request. One way to do this would be to wait until to_representation to load the user information.
My serializer should calculate some values which depend on the user's account.
I subclassed
ModelSerializer
(from wq), and can't find a way to reliably determine therequest
in the constructor (to prepare information forto_representation
method to use for every serialized instance).According to https://stackoverflow.com/a/34617511/1762343, the request should be in
self.context
dict, but I can only (sometimes) find'router': <wq.db.rest.routers.ModelRouter>
there.The text was updated successfully, but these errors were encountered: