私はこの問題に5時間苦労してきましたが、見落としているのは簡単な解決策だと感じています.
一連の送信者と受信者を使用してユーザーアクティビティに関するデータをデータベーステーブルに投稿するサードパーティモジュール ( Django Activity Stream ) を結び付けようとしています。すべてが正しくセットアップおよびインストールされていますが、'Signal' Object has No Attribute 'Save'
実行しようとするとエラーが発生します。
問題は構文のどこかにあると思われます。私はシグナルを使い始めたばかりなので、ベテランがすぐに見つけられるものを見落としている可能性があります。
views.py
私は持っています:
from django.db.models.signals import pre_save
from actstream import action ##This is the third-party app
from models import Bird
def my_handler(sender, **kwargs):
action.save(sender, verb='was saved')
#return HttpResponse("Working Great")
pre_save.connect(my_handler, sender=Bird)
def animal(request):
animal = Bird()
animal.name = "Douglas"
animal.save()
Django アクティビティ ストリーム アプリには次のsignals.py
ファイルがあります。
from django.dispatch import Signal
action = Signal(providing_args=['actor','verb','target','description','timestamp'])
そして、このmodels.py
ファイル:
from datetime import datetime
from operator import or_
from django.db import models
from django.db.models.query import QuerySet
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.timesince import timesince as timesince_
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from actstream import action
...
def action_handler(verb, target=None, **kwargs):
actor = kwargs.pop('sender')
kwargs.pop('signal', None)
action = Action(actor_content_type=ContentType.objects.get_for_model(actor),
actor_object_id=actor.pk,
verb=unicode(verb),
public=bool(kwargs.pop('public', True)),
description=kwargs.pop('description', None),
timestamp=kwargs.pop('timestamp', datetime.now()))
if target:
action.target_object_id=target.pk
action.target_content_type=ContentType.objects.get_for_model(target)
action.save()
action.connect(action_handler, dispatch_uid="actstream.models")