本文整理匯總了Python中notification.models.Notification.action方法的典型用法代碼示例。如果您正苦於以下問題:Python Notification.action方法的具體用法?Python Notification.action怎麽用?Python Notification.action使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類notification.models.Notification
的用法示例。
在下文中一共展示了Notification.action方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: post
# 需要導入模塊: from notification.models import Notification [as 別名]
# 或者: from notification.models.Notification import action [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)