0

我将 django 1.5 与https://github.com/justquick/django-activity-stream一起使用。我做了一个动作。发送喜欢

action.send(request.user, verb="wrote", action_object=Message, target=Group)

并得到这个错误。这是postgres日志:

2013-05-25 08:51:46 PDT ERROR:  column "data" of relation "actstream_action" 
does not exist at character 229
2013-05-25 08:51:46 PDT STATEMENT:  INSERT INTO "actstream_action" 
("actor_content_type_id", "actor_object_id", "verb", "description", 
"target_content_type_id", "target_object_id", "action_object_content_type_id", 
"action_object_object_id", "timestamp", "public", "data") VALUES (9, '2', 'wrote', NULL, 
14, '<property object at 0x25be3c0>', 22, '<property object at 0x25be3c0>', '2013-05-25 
15:51:46.693503+00:00', true, NULL) RETURNING "actstream_action"."id"

我相信代码会执行此操作:

def action_handler(verb, **kwargs):
    """
    Handler function to create Action instance upon action signal call.
    """
    from actstream.models import Action

    kwargs.pop('signal', None)
    actor = kwargs.pop('sender')
    check_actionable_model(actor)
    newaction = 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', now())
    )

    for opt in ('target', 'action_object'):
        obj = kwargs.pop(opt, None)
        if not obj is None:
            check_actionable_model(obj)
            setattr(newaction, '%s_object_id' % opt, obj.pk)
            setattr(newaction, '%s_content_type' % opt,
                    ContentType.objects.get_for_model(obj))
    if settings.USE_JSONFIELD and len(kwargs):
        newaction.data = kwargs
    newaction.save()

动作模型:

class Action(models.Model):
    actor_content_type = models.ForeignKey(ContentType, related_name='actor')
    actor_object_id = models.CharField(max_length=255)
    actor = generic.GenericForeignKey('actor_content_type', 'actor_object_id')

    verb = models.CharField(max_length=255)
    description = models.TextField(blank=True, null=True)

    target_content_type = models.ForeignKey(ContentType, related_name='target',
        blank=True, null=True)
    target_object_id = models.CharField(max_length=255, blank=True, null=True)
    target = generic.GenericForeignKey('target_content_type',
        'target_object_id')

    action_object_content_type = models.ForeignKey(ContentType,
        related_name='action_object', blank=True, null=True)
    action_object_object_id = models.CharField(max_length=255, blank=True,
        null=True)
    action_object = generic.GenericForeignKey('action_object_content_type',
        'action_object_object_id')

    timestamp = models.DateTimeField(default=now)

    public = models.BooleanField(default=True)

# below in models.py
if actstream_settings.USE_JSONFIELD:
    try:
        from jsonfield.fields import JSONField
    except ImportError:
        raise ImproperlyConfigured('You must have django-jsonfield installed '
                            'if you wish to use a JSONField on your actions')
    JSONField(blank=True, null=True).contribute_to_class(Action, 'data')

所以在 action_handler 中,它有 newaction.data = kwargs。为什么将数据属性保存到 db 表中,如何防止这种情况发生?

4

2 回答 2

2

您可以删除该行

'USE_JSONFIELD':真

在您指定 ACTSTREAM_SETTINGS 的 settings.py 中。

ACTSTREAM_SETTINGS = {
    # remove this
    'USE_JSONFIELD': True,
}
于 2016-06-14T07:57:19.063 回答
0

看起来您在 Action 模型中缺少一个“数据”字段。

或者——如果你不想这样,你需要删除它:

  if settings.USE_JSONFIELD and len(kwargs):
    newaction.data = kwargs

为什么不从https://github.com/bradjasper/django-jsonfield(或其他地方)创建一个 JSONField 数据字段?


这是您所缺少的,来自https://github.com/justquick/django-activity-stream/blob/master/actstream/models.py

if actstream_settings.USE_JSONFIELD:
    try:
        from jsonfield.fields import JSONField
    except ImportError:
        raise ImproperlyConfigured('You must have django-jsonfield installed '
                                'if you wish to use a JSONField on your actions')
    JSONField(blank=True, null=True).contribute_to_class(Action, 'data')
于 2013-05-25T16:14:27.773 回答