새로운 ThreadedComments이 나타날 때 사용자에게 알리는 앱을 구축 중입니다. 이를 위해 post_save
신호를 사용하고 있습니다. 여기 내 models.py
: unbound method _get_pk_val() must be called with ThreadedComment instance as first argument (got nothing instead)
:Django 기본 제공 신호 문제 : post_save를 사용할 때의 오류
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from datetime import datetime
from threadedcomments.models import ThreadedComment
from django.db.models.signals import post_save
from blog.models import Post
from topics.models import Topic
class BuzzEvent(models.Model):
user = models.ForeignKey(User)
time = models.DateTimeField(default=datetime.now)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
def __unicode__(self):
return self.content_object
def buzz_on_comment(sender, **kwargs):
# This is called when there is a new ThreadedComment
comment = kwargs['instance']
user_attr_names = {
'post' : 'author',
'topic' : 'creator',
'tribe' : 'creator',
}
user = getattr(comment.content_object,
user_attr_names[comment.content_type.model])
BuzzEvent.objects.create(content_object=sender,
user=user,
time=datetime.now())
post_save.connect(buzz_on_comment, sender=ThreadedComment)
문제는 새로운 ThreadedComment 만들 때, 나는 오류가 발생합니다. 추적 및 디버거는 BuzzEvent 객체를 호출 할 때 signals.pre_init.send
이 호출 될 때 발생한다고 말합니다. 나는 장고 코드를 지금 해킹 할 수 없다. 명백한 해결책이나 아이디어가 있는가?
덕분에 많이 d.m을! – martinthenext