Using Django channel and Rest without signals.

Hi, I am using Django Channels and RestFramework to build a back-end which I can send real time data to a front-end, and my intention is when the database is updated, the front-end endpoint to be updated without it being refreshed, here is my Code so far:

class MyConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        await self.channel_layer.group_add('myCons',self.channel_name)
        await self.accept()

        boat = await self.get_boat(1)
        boat_serializer = BoatSerializer(boat)
        boat_data =

        await self.send(json.dumps({"boat": boat_data,}))

    async def boat_updated(self, event):
        boat_data = event['boat']
        await self.send(json.dumps({"boat": boat_data}))

    def get_boat(self,pk):
        boat =  Boat.objects.get(pk=pk)
        return boat
@receiver(post_save, sender=Boat)
def boat_post_save(sender, instance, **kwargs):
    boat_data = BoatSerializer(instance).data

    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)('myCons', {
        'type': 'boat.updated',
        'boat': boat_data,

And here is my front-end code:
#home.html (can be any front-end client)

  const chatSocket = new WebSocket(
      + '/ws/myconsumer/'
  chatSocket.onmessage = function(e) {
    const data = JSON.parse(;

      const messageElement = document.getElementById('messageContainer');
      messageElement.innerHTML = `
        <h1>My ${}</h1>
        <p>contact: ${}</p>
        <p>Type: ${data.boat.type}</p>
        <p>Serial: ${data.boat.serial}</p>

the code works as expected, However my concern is, I am implementing this with the help of django Signals, is there a way I can accomplish this without using signals. Or can anyone please point me to a right direction,


Yes, you can send a message through the Channel layer from Django to the consumer. See Channel Layers — Channels 4.0.0 documentation, and in particular, the section on Using Outside of Consumers

You’ll have to ensure that this message gets sent anywhere the data gets changed, but it does allows you to handle those situations not covered by a signal.

So depending upon the nature of these updates and possible relationships between models, this may be a more robust solution, but at the expense of there being more work involved.

I dont mind a bit more work, if it is possible. Thanks for the pointers.