알림 앱을 준비했습니다.모든 사용자에게 알림을 보내는 방법은 무엇입니까?
모든 사용자에게 알림을 보내고 싶습니다. 나는이 회선을 사용하는 경우 :
user = models.ForeignKey(User)
는 나에게 내가 선택해야 사용자에게 알림을 보낼 수있는 가능성을 만듭니다.
models.py
from django.db import models
from django.contrib.auth.models import User
class Notifications(models.Model):
title = models.CharField(max_length=150, verbose_name="Tytul")
content = models.TextField(verbose_name="Wiadomosci")
viewed = models.BooleanField(default=False, verbose_name="Otwarta")
user = models.ForeignKey(User)
def __unicode__(self):
return self.title
views.py
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from models import Notifications
def show_notification(request, notification_id):
n = Notifications.objects.get(id=notification_id)
return render_to_response('notifications.html',{'notification':n})
def delete_notification(request, notification_id):
n = Notifications.objects.get(id=notification_id)
n.viewed = True
n.save()
return HttpResponseRedirect('/accounts/loggedin')
.. . 질문이 뭐야? 각 사용자에 대한 알림 개체를 추가하는 방법 – dylrei