@login_required
def notification_update(request):
    flag = request.GET.get('flag', None)
    target = request.GET.get('target', 'box')
    last_notification = int(flag) if flag.isdigit() else None

    if last_notification:

        new_notifications = request.user.notifications.filter(
            id__gt=last_notification).active().prefetch()

        msg = _("Notifications successfully retrieved.") \
            if new_notifications else _("No new notifications.")
        notification_list = []
        for nf in new_notifications:
            notification = nf.as_json()
            notification_list.append(notification)
            notification['html'] = render_notification(
                nf, render_target=target, **notification)

        ctx = {
            "retrieved": len(new_notifications),
            "unread_count": request.user.notifications.unread().count(),
            "notifications": notification_list,
            "success": True,
            "msg": msg,
        }

        return JsonResponse(ctx)

    else:
        msg = _("Notification flag not sent.")

    ctx = {"success": False, "msg": msg}
    return JsonResponse(ctx)
Handles live updating of notifications, follows ajax-polling approach.
dataset/ETHPy150Open v1k45/django-notify-x/notify/views.py/notification_update