Optimize
This commit is contained in:
parent
039778e9a9
commit
5e4791a240
@ -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(
|
||||||
|
21
apps/back/migrations/0004_auto_20210312_1939.py
Normal file
21
apps/back/migrations/0004_auto_20210312_1939.py
Normal 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={},
|
||||||
|
),
|
||||||
|
]
|
@ -2,4 +2,4 @@
|
|||||||
<h1>{{ post.title }}</h1>
|
<h1>{{ post.title }}</h1>
|
||||||
<h2>{{ post.author }}</h2>
|
<h2>{{ post.author }}</h2>
|
||||||
<div>{{ post.content }}</div>
|
<div>{{ post.content }}</div>
|
||||||
</article>
|
</article>
|
Loading…
Reference in New Issue
Block a user