従業員がサポート チームの作業依頼を投稿できるアプリがあります。リクエストフォームが保存されると、サポートチームの担当者に通知が送信されるように構成しようとしています。django-notifications を使用して、management.py ファイルを作成しました...
from django.conf import settings
from django.utils.translation import ugettext_noop as _
if "notification" in settings.INSTALLED_APPS:
from notification import models as notification
def create_notice_types(app, created_models, verbosity, **kwargs):
notification.create_notice_type("post_request", _("Post Request Received"), _("you have received a Post Request"))
signals.post_syncdb.connect(create_notice_types, sender=notification)
else:
print "Skipping creation of NoticeTypes as notification app not found"
しかし、ビュー関数の適切な構文に問題があります。書かれているように:
def create_record(request):
if request.method == 'POST':
form = PostRequestForm(request.POST)
user = User.objects.filter(username="targetuser")
if form.is_valid():
form.save()
if notification:
notification.send([user], "post_request", {"user": user})
return HttpResponseRedirect('/create/')
else:
form = PostRequestForm()
return render(request, 'createpostrequest.html', {
'form': form,
})
しかし、「NoticeType に一致するクエリが存在しません」というエラーがスローされます。「ユーザー」を特定のユーザー名に置き換えると、グローバル名が定義されていないというエラーが発生します。私は何を間違っていますか?