1

I have an application in Django that some users can add and update data. these users add or update data with Django standard forms and views.

I want to implement an other app that send new data to all users when a user update or create data in database. i read about Django-channels that can handle web socket, but i can't find something about server or database events in Django-channels.

So how can i send data to users when a database event occur?

2
  • Can you add your code or whatever you have implemented so far. Commented Mar 17, 2019 at 23:55
  • @Junia . I don't have any code for this app yet. i want to find best way first. Commented Mar 18, 2019 at 20:46

1 Answer 1

1

You can use Signals to detect database events in Django. Take a look at the signals explained here: https://docs.djangoproject.com/en/2.1/topics/signals/

Basically, you'll be doing something along the lines of:

@receiver(post_save, sender=ModelClass)
def my_model_save(sender, instance, **kwargs):
     # this code will be executed after an instance of ModelClass is saved.
     Group(rate_key).send({
            "text": "my message"
     })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.