add database to chatbox

This commit is contained in:
cuom1999 2020-03-19 16:51:56 -06:00
parent cb8eb2689c
commit 112f2b57c3
14 changed files with 77 additions and 104 deletions

View file

@ -1,31 +1,17 @@
from django.http import HttpResponseRedirect
from django.utils.translation import gettext as _
from django.views.generic import ListView
from django.urls import reverse
from django.utils import timezone
from .models import Message
class ChatView(ListView):
model = Message
context_object_name = 'messages'
context_object_name = 'message'
template_name = 'chat/chat.html'
title = _('Chat Box')
paginate_by = 10
def get_context_data(self, **kwargs):
context = super(ChatView, self).get_context_data(**kwargs)
context = super().get_context_data(**kwargs)
context['title'] = self.title
return context
def get_queryset(self):
return None
def send(request):
new_message = Message(body=request.POST['message'],
author=request.profile,
time=timezone.now())
new_message.save()
return HttpResponseRedirect(reverse('chat'))