1

我有一个应用程序,员工可以在其中为支持团队发布工作请求订单。我正在尝试对其进行配置,一旦保存请求表,就会向支持团队的代表发送通知。使用 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 匹配查询不存在”。如果我用特定的用户名替换“用户”,我会得到全局名称未定义错误。我究竟做错了什么?

4

0 回答 0