Subscribe to reverse Foreign Key changes #121
Unanswered
joseluratm
asked this question in
Q&A
Replies: 1 comment 8 replies
-
Sorry it's taken so long to get back to you. You will need to use a filtering based on the user pk. class MyConsumer(AsyncAPIConsumer):
@model_observer(models.event)
async def event_change_handler(
self,
message,
observer=None,
action=None,
subscribing_request_ids=[],
**kwargs
):
for request_id in subscribing_request_ids:
await self.send_json(dict(body=message, action=action, request_id=request_id))
@event_change_handler.groups_for_signal
def classroom_change_handler(self, instance: models.event, **kwargs):
# this block of code is called very often *DO NOT make DB QUERIES HERE*
yield f'-user-event.{instance.assigned_to_id}'
@event_change_handler.groups_for_consumer
def event_change_handler(self, school=None, user=None, **kwargs):
# This is called when you subscribe/unsubscribe
yield f'-user-event.{user.id}'
@action()
async def subscribe_to_events(self, request_id, **kwargs):
# check user has permission to do this
await self.event_change_handler.subscribe(user=self.scope['user'], request_id=request_id) This will mean when users subscribe they subscribe to all changes to Note if an |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, thank you very much for your work. It is a great library!
I am currently facing a casuistica that I do not know if it is because of bad implementation of mine, but I can not find the best solution.
I'll explain my case, to see if you can shed some light on my problem.
Right now I have the following models:
in my web front end, I can assign each of the events to different users. That is to say, a user can have many events assigned to him and an event can only be assigned to one user.
My goal is that I want to be able to be able to receive all signals from events that bind/unbind to a user filtering by the user. This means that only subscription and unsubscription updates per user are sent to each user.
I have tried using the filtering example you specify in the main readme of the project, but I am not able to get it to work. Also, I don't know if that example would be enough to do what I want.
Thank you very much for your help.
Beta Was this translation helpful? Give feedback.
All reactions