def get_context_data(self, **kwargs): ctx = super(ChatRoomView, self).get_context_data(**kwargs) label = self.kwargs.get('label') print 'label:', label room = Room.objects.get(label=label) ctx['room'] = room ctx['messages'] = Message.top_messages(room) return ctx
def db(): try: User.create_table() Message.create_table() except Exception: pass
import datetime from example.models import Message, Sender sender = Sender(name="Me Myself", email="*****@*****.**", imageUrl="") sender.save() recipient = Sender(name="You Yourseld", email="*****@*****.**", imageUrl="") recipient.save() message = Message(sender=sender, recipient=recipient, message="Hello! How are you?", timestamp=datetime.datetime.now()) message.save()
def bulk_delete(handler, request): """Bulk delete items""" ids = request.GET.getall('ids') Message.delete().where(Message.id << ids).execute() raise muffin.HTTPFound(handler.url)