2013-03-21 2 views
1

나는 django-notification을 사용하여 이메일을 보내려고합니다. 필자는 문서를 읽고 모든 통지 유형, 템플리트 및 management.py를 작성했습니다. 그러나 전자 메일을 보내려고하면 오류와 함께이 디버그 페이지가 표시됩니다. NoticeType 일치하는 쿼리가 없습니다. 여기에 몇 가지 코드가 있습니다. 내 models.py 파일에서django-notification 오류 : NoticeType 일치하는 쿼리가 존재하지 않습니다?

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.admin', 
    'departments', 
    'notification' 
) 

EMAIL_USE_TLS = True 
EMAIL_HOST = 'smtp.gmail.com' 
EMAIL_HOST_USER = '[email protected]' 
EMAIL_HOST_PASSWORD = #not shown 
EMAIL_PORT = 587 
NOTIFICATION_BACKENDS = [("[email protected]", "notification.backends.email.EmailBackend"),] 
#other code.... 

: 내 settings.py 파일에서

from django.conf import settings 
from django.db.models import signals 
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.NoticeType.create("create_model", _("Model Creation"), _("An entry has been created")) 
     notification.NoticeType.create("delete_model", _("Model Deletion"), _("An entry has been deleted")) 
     notification.NoticeType.create("edit_model", _("Model Change"), _("An entry has been changed.")) 
    signals.post_syncdb.connect(create_notice_types, sender=notification) 
else: 
    print "Skipping creation of NoticeTypes as notification app not found" 

: 내 management.py 파일에서

과부하에 대한

def model_create_edit(sender, **kwargs): 
     instance = kwargs.get('instance') 
     user, first_name, last_name = instance.user, instance.user.first_name, instance.user.last_name 
     if kwargs['created']: 
      notification.send([user], "create_email", {'user':user, 'first':first_name, 'last':last_name}) 

     else: 
      notification.send([user], "edit_email", {'user':user, 'first':first_name, last':last_name})   

def model_deletion(sender, **kwargs): 
     instance = kwargs.get('instance') 
     user, first_name, last_name = instance.user, instance.user.first_name, instance.user.last_name 
     notification.send([user], "delete_email", {'user':user, 'first':first_name, 'last':last_name}) 

죄송합니다 코드가있는 페이지. 거기에 내가 잘못하고있는 것이 있습니까? 뭐가 없니? 어떤 통찰력이라도 대단히 감사하겠습니다!

+0

'./manage.py syncdb'를 실행 했습니까? –

+0

그래, 나는 통지 유형이 admin 백엔드를 검사하여 만들어 졌는지 확인했다. – Kenny

+2

잠깐, "create_model"알림 유형을 만들고 있지만 "create_email"알림 유형을 보내면 문제가 될 수 있습니까? –

답변

0

NoticeType 개체에 존재하지 않는 것을 할당하려고하기 때문에이 현상이 발생합니다. 문제는 코드의 어느 부분이 그 부분을하는지 이해할 수 없지만 try:, except:을 추가하면 문제가 해결됩니다. 쿼리를 추가하여 일치시킬 때마다 시도해보고 쿼리를 찾습니다.

0

create_model, delete_model, edit_modelNoticeType을 생성했기 때문에 이러한 현상이 발생합니다. notifications.send을 사용하여 알림을 전송할 때 다른 라벨 : create_email 등을 사용하고 있습니다. 라벨은 먼저 만든 라벨과 동일해야합니다. create_mailcreate_model notification.send([user], "create_model", {'user':user, 'first':first_name, 'last':last_name})으로 변경해야합니다.