How do I transmit any changes to databases(i.e. creates and updates pertaining to a particular user) using Django Channels?

7 views
Skip to first unread message

Alexis Candelaria

unread,
Mar 8, 2018, 8:10:12 AM3/8/18
to Django users
My goal is to send send any database updates to the relevant users. I was thinking of utilizing the views of the post and patch requests to do this but am not sure if there is better or more documented way. 

Andrew Godwin

unread,
Mar 8, 2018, 8:19:55 AM3/8/18
to django...@googlegroups.com
Hi Alexis,

You'll need to do some work yourself - hook into database changes (either via signals or overriding the save method) to send change notifications to a different Group for each user (maybe use group names like "user-123213", where the number is their ID).

Then, when someone connects via a socket or long-poll, add their consumer to the group and listen for the change message. You can see some docs on this here: http://channels.readthedocs.io/en/latest/topics/channel_layers.html and an example of sending messages to groups (albeit from another consumer rather than a save method) here: https://github.com/andrewgodwin/channels-examples/tree/master/multichat

Andrew

On Thu, Mar 8, 2018 at 7:35 AM, Alexis Candelaria <alexisca...@gmail.com> wrote:
My goal is to send send any database updates to the relevant users. I was thinking of utilizing the views of the post and patch requests to do this but am not sure if there is better or more documented way. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b8810aad-de6b-4fb3-b1b6-06547d4e2d6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages