Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Feb 10, 2023 · 4 comments

Comments

@tamhv
Copy link

tamhv commented Feb 10, 2023

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
Copy link
Collaborator

auvipy commented Feb 10, 2023

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

@justquick
Copy link
Owner

did you register your user model for use with actstream?

@tamhv
Copy link
Author

tamhv commented Feb 13, 2023

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
Copy link

pembo13 commented Mar 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants