M
M
Meekey2018-09-05 19:23:43
Django
Meekey, 2018-09-05 19:23:43

How to set up sending json objects to Django Channels?

How to set up sending json objects to Django Channels? So that when adding a new object in the admin panel, it immediately appears on the front in real time. Maybe someone has some examples. I would be very grateful.
There is a Factory object:
models.py

class Factory(models.Model):

    OBJECT_CHOICES = (
            ('Завод', 'Завод'),
            ('Вышка', 'Вышка'),
            ('Хранилище', 'Хранилище'),
            ('АЗС', 'АЗС')
        )

    title = models.CharField(max_length=200)
    choice = models.CharField(max_length=15, choices=OBJECT_CHOICES, default = '')
    address = YmapCoord(max_length=200, start_query=u'Россия', size_width=500, size_height=500, unique = True)

With a GET request to /getFactory/, JSON is issued like
[
   {
    "title": "factory",
    "choice": "Завод",
    "address": [
        55.744607932133505,
        48.99357300960071
    ]
   }
]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question