【问题标题】:how to make notification icon - django如何制作通知图标 - django
【发布时间】:2023-02-10 23:27:09
【问题描述】:

导航栏.html

{% load custom_tags %}            
 <div id="noti">
    <i class="fa fa-bell" aria-hidden="true">{% show_notifications %}</i>
 </div>

模板标签/custom_tags.py

from django import template
from nol.models import Notification

register = template.Library()

@register.inclusion_tag('notification/show_notification.html', takes_context=True)
def show_notifications(context):
    request_user = context['request'].user
    notifications = Notification.objects.filter(to_user=request_user).exclude(user_has_seen=True).order_by('-date')
    return {'notifications': notifications}

模型.py

class Notification(models.Model):
    notification_type = models.IntegerField()
    to_user = models.ForeignKey(CustomUser, related_name='notification_to', on_delete=models.CASCADE, null=True)
    from_user = models.ForeignKey(CustomUser, related_name='notification_from', on_delete=models.CASCADE, null=True)
    date = models.DateTimeField(default=timezone.now)
    user_has_seen = models.BooleanField(default=False)

我正在尝试发出通知,但如何将通知铃与计数联系起来?

【问题讨论】:

    标签: python django


    【解决方案1】:

    之前有人问过这个问题,

    这是解决方案 [https://stackoverflow.com/questions/72264677/how-can-i-implement-notifications-system-in-django]

    【讨论】:

      猜你喜欢
      • 2012-07-16
      • 1970-01-01
      • 1970-01-01
      • 2011-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多