Mojimi
Mojimi

Reputation: 3171

Django server-sent events in 2016

I'm trying to set up a multi user edit session, using server-sent events to warn the user that someone else is also editing that object (like in google docs)

class Edit_Session(models.Model):
    #uuid is a global unique field for all models
    object_uuid = models.UUIDField(primary_key=True)
    user = models.OneToOneField(User, on_delete=models.CASCADE)

So all I need is to send a message to the client if there is someone else editing the same uuid as him.

I've read about websockets, tornado, twisted and all that, but is there a simpler way to achieve this in Django that doesn't involve having to learn another library and figure out how to integrate them with Django?

Upvotes: 1

Views: 815

Answers (1)

Withnail
Withnail

Reputation: 3178

"Is there another way to do this... without learning another library and integrate it with Django?"

Short answer, not yet.

Longer answer: The correct way to do this in Django will be to use Django-Channels, which uses websockets. Channels has been adopted as an official Django Project, and will be supported (and maybe integrated at some point) over the next few releases.

There is a great list of example project available from Andrew Godwin's github.

Yes, it's another library, but it's as close to batteries-included-django as you'll get for doing this kind of work.

Upvotes: 3

Related Questions