Django Channel web sockets - append message to Model.objects -


lately, i've been investigating onto integrating web sockets django. according documentation, using channels way go.

given illustrative model query

class request(models.model):     id = models.integerfield(name="id", primary_key=true)     query = models.charfield(name = 'query', max_length=1024) 

i want have web application connected web socket server. when web socket server receives message, should broadcast message particular subset of socket connections established client.

the client (namely web browser), once receiving broadcasted message, should append request.objects. there on, list of queries should automatically updated using django templates , within defined model - without forcing user explicitly refresh it.

hence, questions of mine are: (i) using channels (if preferred way of dealing web socket connections in django), how can append newly arrived query object query.objects - without storing object database because has been inserted prior sending web socket server, (ii) refresh content of corresponding django template.

django-channels new way connecting django backend django frontend.

your second question i'm not understand inside consumer functions can import models , update database

# consumers.py  def hello(message):     obj = request.objects..     obj.save()     message.reply_channel.send({         "text": message.content['text'],     }) 

and can update template using jquery...

<p></p> socket.onmessage = function(e) {     $('p').html(e.data); } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -