add database to chatbox

This commit is contained in:
cuom1999 2020-03-19 16:51:56 -06:00
parent cb8eb2689c
commit 112f2b57c3
14 changed files with 77 additions and 104 deletions

View file

@ -1,5 +1,3 @@
# based on https://github.com/narrowfail/django-channels-chat
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from django.db import models
@ -18,19 +16,10 @@ class Message(models.Model):
time = models.DateTimeField(verbose_name=_('posted time'), auto_now_add=True)
body = models.TextField(verbose_name=_('body of comment'), max_length=8192)
def notify_ws_clients(self):
notification = {
'type': 'recieve_group_message',
'message': '{}'.format(self.id)
}
channel_layer = get_channel_layer()
def save(self, *args, **kwargs):
new_message = self.id
self.body = self.body.strip()
super(Message, self).save(*args, **kwargs)
if new_message is None:
self.notify_ws_clients()
class Meta:
app_label = 'chat_box'