I need to display a feed for a user for a set of actions. I'm using Django Activity Stream for this. I just started to test the application but I can't seem to display the users feed.
我需要为用户显示一组操作的Feed。我正在使用Django Activity Stream。我刚刚开始测试应用程序但我似乎无法显示用户提要。
As per the Action Stream documentation I'm using the actor_stream
function as follows
根据Action Stream文档,我使用了actor_stream函数,如下所示
from actstream.models import actor_stream
def user_feed(request):
print actor_stream(request.user)
This gives me a error
这给了我一个错误
ValueError at /feed/
invalid literal for int() with base 10: '<property object at 0x2a6a520>'
Here is the traceback
这是追溯
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jaskaran/coding/buyingiq/authentication/feed/views.py" in user_feed
7. print actor_stream(request.user)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __repr__
71. data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __iter__
96. self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _fetch_all
856. self._prefetch_related_objects()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _prefetch_related_objects
517. prefetch_related_objects(self._result_cache, self._prefetch_related_lookups)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in prefetch_related_objects
1598. obj_list, additional_prl = prefetch_one_level(obj_list, prefetcher, attr)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in prefetch_one_level
1697. prefetcher.get_prefetch_queryset(instances)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/generic.py" in get_prefetch_queryset
96. ret_val.extend(ct.get_all_objects_for_this_type(pk__in=fkeys))
File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py" in get_all_objects_for_this_type
174. return self.model_class()._base_manager.using(self._state.db).filter(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in filter
590. return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _filter_or_exclude
608. clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in add_q
1198. clause = self._add_q(where_part, used_aliases)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in _add_q
1234. current_negated=current_negated)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in build_filter
1125. clause.add(constraint, AND)
File "/usr/local/lib/python2.7/dist-packages/django/utils/tree.py" in add
104. data = self._prepare_data(data)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py" in _prepare_data
79. value = obj.prepare(lookup_type, value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py" in prepare
352. return self.field.get_prep_lookup(lookup_type, value)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_prep_lookup
371. return [self.get_prep_value(v) for v in value]
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_prep_value
613. return int(value)
Exception Type: ValueError at /feed/
Exception Value: invalid literal for int() with base 10: '<property object at 0x2a6a520>'
print type(actor_stream(request.user))
evaluates to <class 'actstream.gfk.GFKQuerySet'>
print类型(actor_stream(request.user))求值为
I even tried typcasting it as a list and then printing it but it still throws the same error. How should I be accessing the actor stream in my view?
我甚至尝试将它打印为列表然后打印它但它仍然会抛出同样的错误。我应该如何在视图中访问actor流?
EDIT - I'm using a Custom User Model if that makes any difference.
编辑 - 我正在使用自定义用户模型,如果这有任何区别。
EDIT 2 - Traceback for using Eliot's solution
编辑2 - 使用Eliot解决方案的回溯
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
101. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
318. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
346. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
341. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/home/jaskaran/coding/buyingiq/authentication/authentication/urls.py" in <module>
7. admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/usr/local/lib/python2.7/dist-packages/allauth/account/admin.py" in <module>
9. class EmailAddressAdmin(admin.ModelAdmin):
File "/usr/local/lib/python2.7/dist-packages/allauth/account/admin.py" in EmailAddressAdmin
16. 'last_name'])))
File "/usr/local/lib/python2.7/dist-packages/allauth/account/admin.py" in <lambda>
13. filter(lambda a: a and hasattr(User(), a),
File "/home/jaskaran/coding/buyingiq/authentication/users/models.py" in __init__
86. return self.pk
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in _get_pk_val
465. return getattr(self, meta.pk.attname)
Exception Type: AttributeError at /feed/
Exception Value: 'UserProfile' object has no attribute 'id'
1 个解决方案
#1
0
What if you do instead :
如果你做了怎么办:
from actstream.models import actor_stream
def user_feed(request):
print actor_stream(request.user.pk) # added .pk here
As you can see at the end of the stacktrace (return int(value)
), django try to convert request.user
to an integer. I think it fails because you use a custom User model, and have not any __int__
method defined in it. Try to had this method in your User model :
正如您在stacktrace(return int(value))的末尾所看到的,django尝试将request.user转换为整数。我认为它失败了,因为您使用自定义用户模型,并且没有定义任何__int__方法。尝试在您的用户模型中使用此方法:
class UserModel(models.Model):
class UserModel(models.Model):
# your logic here
def __int__(self):
return self.pk
#1
0
What if you do instead :
如果你做了怎么办:
from actstream.models import actor_stream
def user_feed(request):
print actor_stream(request.user.pk) # added .pk here
As you can see at the end of the stacktrace (return int(value)
), django try to convert request.user
to an integer. I think it fails because you use a custom User model, and have not any __int__
method defined in it. Try to had this method in your User model :
正如您在stacktrace(return int(value))的末尾所看到的,django尝试将request.user转换为整数。我认为它失败了,因为您使用自定义用户模型,并且没有定义任何__int__方法。尝试在您的用户模型中使用此方法:
class UserModel(models.Model):
class UserModel(models.Model):
# your logic here
def __int__(self):
return self.pk