1
follow()
함수가 UserProfile에서 호출 될 때 신호를 사용하고 싶습니다. 다른 모델 (저장시)과 작동하는 신호를 작성했습니다. UserProfile
모델을 저장할 때m2m_changed에서 신호 사용
class UserProfile(UserenaBaseProfile):
user = models.OneToOneField(User,unique=True,verbose_name=_('user'))
location = models.CharField(_('Location'), max_length=255, blank=True, default='')
following = models.ManyToManyField(User, verbose_name=_('following'), related_name='followers', blank=True, null=True)
def follow(self, user):
self.following.add(user)
def unfollow(self, user):
self.following.remove(user)
신호
def follow_action(sender, instance, created, action_object=None, **kwargs):
action.send(instance.user, verb='follows', target=instance.content_object)
post_save.connect(follow_action, sender=UserProfile)
이 신호가 작동합니다. follow()
함수가 실행될 때 신호를 호출하려고합니다. 너는 도와 줄 수 있니? 어떤 생각? 그것은 작동하지 않습니다
def follows_action(sender, instance, created, action_object=None, **kwargs):
action.send(instance.user, verb='follows', target=instance.content_object)
m2m_changed.connect(follows_action, sender=UserProfile.following.through)
: 감사
UPDATE를 많이. 내가 놓친 게 있니?
django-activity-stream (action.send)을 사용하는 것처럼 보입니다. 왜 Follow 모델이 아닌 UserProfile 모델을 사용합니까? – jpic
@jpic 당신 말이 맞아요. 'django-activity-stream'을 사용하고 있습니다. – Kulbir
아마도 follows_action의 서명이 잘못 되었기 때문에 아마도 작동하지 않습니다. 링크 된 문서에 설명 된 예외적 인 m2m_changed 콜백 서명과 일치하지 않습니다. 나는 거짓말하지 않을 것이다, 당신이 많이 시도한 것처럼 보이지 않는다. 멋진 경험을 원한다면 [해커 하우투] (http://www.catb.org/~esr/faqs/hacker-howto.html) – jpic