add time format for chat box

This commit is contained in:
cuom1999 2020-03-20 15:34:33 -06:00
parent 112f2b57c3
commit dd34f474a5
4 changed files with 45 additions and 22 deletions

View file

@ -1,6 +1,7 @@
import json
from channels.generic.websocket import AsyncWebsocketConsumer
from .models import Message
from .views import format_time
from judge.models.profile import Profile
@ -60,5 +61,3 @@ def save_data_and_get_time(message):
return new_message.time
def format_time(time):
return time.strftime('%H:%M %p %d-%m-%Y')

View file

@ -4,14 +4,22 @@ from django.views.generic import ListView
from .models import Message
def format_time(time):
return time.strftime('%H:%M %p %d-%m-%Y')
class ChatView(ListView):
model = Message
context_object_name = 'message'
template_name = 'chat/chat.html'
title = _('Chat Box')
paginate_by = 10
paginate_by = 50
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = self.title
for msg in context['message']:
msg.time = format_time(msg.time)
return context