Wednesday, April 26, 2017

Re: Multiplex results from (Django-Channels)

I only have limited time for free advice, unfortunately, so I can't help you write everything! However, it looks like your problem is that you are trying to add to a group called:

'chat-' + listrooms

Where listrooms is a queryset - that doesn't make any sense. You need a for loop instead.

Andrew

On Wed, Apr 26, 2017 at 4:49 PM, Yarnball <yconomos@gmail.com> wrote:
Thanks Andrew. I took your advice. I cloned and looking into the example, and tried what you suggested. 

In my case, the chat is persistent.

I will not be doing it via URL, instead I'm doing a queryset to get all the rooms a user belongs to.

However, it still isn't working. Could you please advise?

@channel_session
def ws_connect(message):
    listrooms
= User.objects.filter(chat__isnull=False).values('chat')
    # `listrooms` gives the PK fields of the chat rooms
    chathistory = room.messages.all().order_by('timestamp')

   
Group('chat-' + listrooms).add(message.reply_channel)
    message.channel_session['listrooms'] = list(set(message.channel_session['listrooms']).union([room.id]))
    message
.reply_channel.send({'text': json.dumps([msg.as_dict() for msg in chathistory.all()])})




@channel_session
def ws_receive(message):
    listrooms
= User.objects.filter(chat__isnull=False).values('chat')
    data
= json.loads(message['text'])
    m
= listrooms.messages.create(handle=data['handle'], message=data['message'])
   
Group('chat-'+ listrooms).send({'text': json.dumps([m.as_dict()])})

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/529472b1-9323-45d8-951e-f5729472bb66%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFwN1upu3MfmFn1d%3D-DvsQJyxs4esdBac8KPV_Qoujfbq9wSoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment