在我的员工用户上,我试图制作一个模块,用于将响应发送给特定用户,然后该用户将收到有关我刚刚发送的响应的通知。
我已经有一个用于向用户发送响应的模块,该模块可以为所有活动用户选择用户名。而且我还有一个用于通知用户的模块。
models.py
class UserNotification(models.Model):
sender=models.ForeignKey(User,on_delete=models.CASCADE,related_name='user_sender',default='')
receiver=models.ForeignKey('custom_user.User',on_delete=models.CASCADE,related_name='user_receiver',default='')
concern_type = models.CharField(max_length=100,choices=CHOICES)
content = models.TextField(max_length=255,blank=False)
date_sent = models.DateTimeField(default = timezone.now)
forms.py
class SendNotificationForm(forms.ModelForm):
class Meta:
model = UserNotification
fields = ['receiver','concern_type','content']
views.py
def user_notifications(request):
notifications = UserNotification.objects.all().order_by('-date_sent')
context = { 'notifications':notifications }
template_name = [
'notification.html',
]
return render(request,template_name,context)
当我尝试发送回复并选择用户的用户名以接收该通知时。该通知始终广播给所有用户。我知道我的应用程序中仍然有更多的代码不足,但我只是想知道您对我的问题有何看法。