-
First of all thanks for this great library. It made a lot of stuff I have to handle much easier. But now I'm confronted with a hard-to-solve problem. I have a many-to-many relationship and want to subscribe to all the children. Just like the documentation (https://github.com/hishnash/djangochannelsrestframework#subscribing-to-a-filtered-list-of-models) shows. But I can't think of a way to implement the Let's say my models look like this:
(https://docs.djangoproject.com/en/3.2/topics/db/examples/many_to_many/) To get the
But as stated in the documentation this doesn't seem to be a good idea. Is there a better way that I forgot? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
yer this is not a trival situation. maybe what you could do is: When subsceribing subscribe to all Articles (assume this is a small enough list... not in the 1000s)
In the consume when you detect a change to a ManyToMany table (eg a new article is created) subscribe to that article. Or if the many to many table is updated and the article is removed from the publication un-subscribe from the articles changes. does this make any sense? happy to mock up how this migh look in code if you need? (if you expect there to be many articles then we need to come up with a differnt solution) Go through your code and ensure the many to many table is also included as a prefetch related (this way you could emmmit an event for every single publication without doing extra db quries). |
Beta Was this translation helpful? Give feedback.
-
Hi, thanks for the ideas. |
Beta Was this translation helpful? Give feedback.
-
@j0nm1 I know it has been a long time since you question but I wanted to follow up for those reading this in the future. As of v1.3 we now have M2m support with model observers. To enable this you do: @model_observer(Article, many_to_many=True) this will result in you getting update notifications when the many to many relationship is updated. |
Beta Was this translation helpful? Give feedback.
@j0nm1 I know it has been a long time since you question but I wanted to follow up for those reading this in the future.
As of v1.3 we now have M2m support with model observers. To enable this you do:
@model_observer(Article, many_to_many=True)
this will result in you getting update notifications when the many to many relationship is updated.