Now i have my below views to read and update notifications when recieved by the user, and i am basically using ajax to update them.
but then learnd about python Engineio, now how will i able to implement this on my django vews and website as to send and recieve notifications in real time.
my views
def show_notifications(request, username):
if is_ajax(request=request):
if request.user.is_authenticated:
user = User.objects.get(username=username)
unread_notifications = list(Notification.objects.select_related('received_by').filter(received_by=user, read = False).values_list('message', flat=True).order_by("-created_at"))
read_notifications = list(Notification.objects.select_related('received_by').filter(received_by=user, read = True).values_list('message', flat=True).order_by("-created_at"))
return JsonResponse({"unread_notifications": unread_notifications,
"read_notifications": read_notifications})
def update_notifications(request, username):
if is_ajax(request=request):
if request.user.is_authenticated:
user = User.objects.get(username=username)
notifications = Notification.objects.select_related('received_by').filter(received_by=user, read=False).update(read=True)
return JsonResponse({'status': 'Notifications updated'})