This commit is contained in:
Andros Fenollosa 2021-03-12 21:21:01 +01:00
parent 039778e9a9
commit 5e4791a240
3 changed files with 24 additions and 12 deletions

View File

@ -7,20 +7,11 @@ class BlogConsumer(WebsocketConsumer):
def connect(self): def connect(self):
''' Cliente se conecta ''' ''' Cliente se conecta '''
# Recoge el nombre de la sala
self.room_name = self.scope["url_route"]["kwargs"]["room_name"]
self.room_group_name = "blog_%s" % self.room_name
# Se une a la sala
self.channel_layer.group_add(self.room_group_name, self.channel_name)
# Informa al cliente del éxito
self.accept() self.accept()
def disconnect(self, close_code): def disconnect(self, close_code):
''' Cliente se desconecta ''' ''' Cliente se desconecta '''
# Leave room group pass
self.channel_layer.group_discard(self.room_group_name, self.channel_name)
def receive(self, text_data): def receive(self, text_data):
''' Cliente envía información y nosotros la recibimos ''' ''' Cliente envía información y nosotros la recibimos '''
@ -39,7 +30,7 @@ class BlogConsumer(WebsocketConsumer):
data['pag'] = pag data['pag'] = pag
if template == "partials/blog/single.html": if template == "partials/blog/single.html":
data["post"] = Post.objects.get(data['id']) data["post"] = Post.objects.get(pk=data['id'])
# Send message to WebSocket # Send message to WebSocket
self.send( self.send(

View File

@ -0,0 +1,21 @@
# Generated by Django 3.1.7 on 2021-03-12 19:39
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('back', '0003_auto_20210309_2038'),
]
operations = [
migrations.AlterModelOptions(
name='comment',
options={},
),
migrations.AlterModelOptions(
name='post',
options={},
),
]