S
S
s1vemod2021-07-22 17:37:28
Django
s1vemod, 2021-07-22 17:37:28

How can I work with WebSockets?

Good evening.

I am writing an admin panel on Vue + Django, the data that comes from the site itself should appear dynamically in the panel.
They communicate via WebSocket, how can I track the creation of a new object in the database, and then kick the WebSocket?
Is it possible to do this through signals? Didn't find an implementation* A

POST request flies from the site, which creates a new object in the database, after which I need to immediately display this object in the admin panel.

Also, what can I use as the first argument when creating a group?

await self.channel_layer.group_add(
            self.?,
            self.channel_name
        )

After all, I do not have any data, except for the user ID that is currently logged into the admin panel. It's possible that I don't fully understand how this works.

Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2021-07-22
@s1vemod

Yes, it turns out - https://django.fun/tutorials/django-websockety-ic...
PS...
One of the options is to give json and work through ajax. Immediately after sending the object via ajax, it requests the re-updated data, also via ajax. And yes, in this case, little is left of Django itself, except for ORM :-)
The second option is to install an independent websocket application where to shove data from the backend, and already pick it up at the front.
For as I remember, django does not know how to use websocket, but I could be wrong.
The third option - do you need django if vue is running on the front? Maybe immediately on aiohttp?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question