justquick / django-activity-stream

Generate generic activity streams from the actions on your site. Users can follow any actors' activities for personalized streams.
http://django-activity-stream.rtfd.io/en/latest/
BSD 3-Clause "New" or "Revised" License
2.38k stars 482 forks source link

Field 'actor' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation. #525

Open tamhv opened 1 year ago

tamhv commented 1 year ago

Hi everyone, i'm playing with django-activity-stream docs Custom Action Data https://django-activity-stream.readthedocs.io/en/latest/data.html and i found an issue, i seem can't query Action like the docs describe.

env

Django==3.2.9
django-activity-stream==1.4.2

setup

    def ready(self):
        from actstream import registry
        registry.register(apps.get_model(settings.AUTH_USER_MODEL))

django shell

In [9]: action.send(u,verb='started testing activity')
Out[9]: [(<function actstream.actions.action_handler(verb, **kwargs)>,
  <Action: system.admin started testing activity 0 minutes ago>)]
...
In [15]: user_stream(u, with_user_activity=True)
Out [15]: <GFKQuerySet [<Action: system.admin started testing activity 2 minutes ago>]>
...
In [47]: Action.objects.get(actor=u)
ERROR...
FieldError: Field 'actor' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation.
auvipy commented 1 year ago

where you are suggesting to use GenericRelation? can you elaborate more please?

justquick commented 1 year ago

did you register your user model for use with actstream?

tamhv commented 1 year ago

i just set up a small demo to try it again here https://github.com/tamhv/dasdemo still no luck

@auvipy i just want to make sure i've done full settings of django-activity-stream for my project, i copied and run a query from django-activity-stream documentation, section Custom Action Data, it showed the above error.

action = Action.objects.get(verb='answered', actor=galahad, target=bridgekeeper)
action.data['favorite_color']
'Blue. No, yel... AAAAAAA'
action.data['quest'] = 'To seek the Holy Grail'
action.save()
action.data
{'favorite_color': 'Blue. No, Green - AAAAAAA', 'quest': 'To seek the Holy Grail'}

@justquick yes i did, i can do action.send and query user_stream without issues, i tried to use registry.check to check it.

pembo13 commented 7 months ago

Any update on this? I'm trying to follow the example. I've verified that setup_generic_relations gets called on the User model, but actions = Action.objects.filter(actor=user) does not work.

Field 'actor' does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation.