本文整理汇总了Python中notification.models.Notification.recipient方法的典型用法代码示例。如果您正苦于以下问题:Python Notification.recipient方法的具体用法?Python Notification.recipient怎么用?Python Notification.recipient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类notification.models.Notification
的用法示例。
在下文中一共展示了Notification.recipient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from notification.models import Notification [as 别名]
# 或者: from notification.models.Notification import recipient [as 别名]
def post(self,request):
form=QuestionForm(data=request.POST)
if form.is_valid():
question=Question(title=form.cleaned_data['title'],content=form.cleaned_data['content'])
question.author=request.user.profile
question.save()
for tagtitle in form.cleaned_data['tags']:
try:
tag=Tag.objects.get(name=tagtitle)
except ObjectDoesNotExist:
tag=Tag()
tag.name=tagtitle
tag.save()
question.tags.add(tag)
tag.save()
question.author.rank+=0.01
question.save()
question.author.save()
#notification
users_notification=[]
for tag in question.tags.all():
if tag.tag_followers.all().count() > 0:
for profile in tag.tag_followers.all():
if profile!=request.user.profile and profile not in users_notification:
#create notification
notification=Notification()
notification.sender=request.user.profile
notification.recipient=profile
notification.action='addquestion'
notification.content_object=question
notification.save()
users_notification.append(profile)
for follower in request.user.profile.followers.all():
if follower not in users_notification:
notification=Notification()
notification.sender=request.user.profile
notification.recipient=follower
notification.action='addquestion'
notification.content_object=question
notification.save()
return HttpResponseRedirect(reverse('question:detail',args=(question.pk, question.slug)))
else:
args={}
args['form']=form
args.update(csrf(request))
return render(request,'question_add.html',args)