Replies: 1 comment
-
nWith any subscribtion there are 2 stages of serializing.
This means durring the first serialization there is no user infomation known (as it will be sent to many subscirbers). For this reason I do not use DRF serializer and by default just pass the In the second stage this code is called once for every subscribed connection so we do have acccess to user infomation and can use regulare DRF serializers. If you expect to have lots and lots of subscribers to the same event (and do not need to filter the response based on the user info) then you should do the serialization in the first stage as you have. However if you do not expect to have many subscriers so the cost of the extra DB calls for each subscriber is low then you should do in inthe second pass. the body of your However you might be better of using one of the generic mixins can you explain more about your aim here? are you subscribing to a list (all instance, a filtered subset? or just a single one by instance id?) |
Beta Was this translation helpful? Give feedback.
-
I'm trying to figure out if there's a way to run the response through my stacked serializers? This is my current code, but seems excessive to do when I should be able to serialize the data. Sorry if its been asked, but im not understanding enough from the README. Im also having issues subscribing to a ForeignKey, but maybe its an error ive made.
`
@notify_change_handler.serializer
def notify_change_handler(self, instance: Notifications, action, **kwargs):
if action == 'delete':
return {"pk": instance.pk}
`
Beta Was this translation helpful? Give feedback.
All reactions