Django-channels save reply channel to django model field?

363 views
Skip to first unread message

Nikoleta Misheva

unread,
Jan 19, 2017, 9:57:56 AM1/19/17
to Django users
Hello, sorry to bother you but how do you make a django-channels  Channel field in a Django model? I tried to use ForeignKey and ForeignObject but doesn't do the work.
Thank you in advance :)

Andrew Godwin

unread,
Jan 19, 2017, 1:25:41 PM1/19/17
to django...@googlegroups.com
Hi,

Channel isn't a field type - it's a separate datastructure entirely from a database/Django models and is powered by its own code and servers (the channel layer).

If you want to persist the name of a reply_channel for use later, like knowing what channel connections are on to send information down, then use a CharField(max_length=255), and put the name of the channel in that (which is usually reply_channel.name). You can then take the string name and pass it to channel to make it again like Channel(reply_channel_name).

Hope that helps,
Andrew

On Thu, Jan 19, 2017 at 6:57 AM, Nikoleta Misheva <nith...@gmail.com> wrote:
Hello, sorry to bother you but how do you make a django-channels  Channel field in a Django model? I tried to use ForeignKey and ForeignObject but doesn't do the work.
Thank you in advance :)

--
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...@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/ace270a5-ccba-43b2-aa54-bc425de9f709%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nikoleta Misheva

unread,
Jan 19, 2017, 1:52:38 PM1/19/17
to Django users
So for example when I need the reply channel in the ws recieve method I need to create the Channel again and it will be the same channel referring to the same user? And do I have to delete the newly created channel after each ws recieve method?


четвъртък, 19 януари 2017 г., 20:25:41 UTC+2, Andrew Godwin написа:
Hi,

Channel isn't a field type - it's a separate datastructure entirely from a database/Django models and is powered by its own code and servers (the channel layer).

If you want to persist the name of a reply_channel for use later, like knowing what channel connections are on to send information down, then use a CharField(max_length=255), and put the name of the channel in that (which is usually reply_channel.name). You can then take the string name and pass it to channel to make it again like Channel(reply_channel_name).

Hope that helps,
Andrew
On Thu, Jan 19, 2017 at 6:57 AM, Nikoleta Misheva <nith...@gmail.com> wrote:
Hello, sorry to bother you but how do you make a django-channels  Channel field in a Django model? I tried to use ForeignKey and ForeignObject but doesn't do the work.
Thank you in advance :)

--
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...@googlegroups.com.

Andrew Godwin

unread,
Jan 19, 2017, 2:36:04 PM1/19/17
to django...@googlegroups.com
Channels don't need to be deleted, they're just pointers. And yes, if you make a channel with the same name as a reply channel, it will function the same - all channels are, are strings put onto messages as a sort of header for routing and queuing purposes.

Andrew

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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages