Filter Action Error: Field 'actor' does not generate an automatic reverse relation and therefore cannot be used for reverse querying.
See original GitHub issueHey every one (@justquick),
I have a django app and now I want to introduce django-activity-stream to notify users from events.
My issue is that I can not filter
actions by actor
or target
:
python3.5 shell
>>> from app import models
>>> a = models.MyAppUser.objects.all()[1]
>>> a
<MyAppUser: Mark>
>>> t = models.MyAppUser.objects.all()[2]
>>> t
<MyAppUser: Steve>
>>> from actstream.models import Action
>>> Action(actor=a, verb='POST', target=t)
<Action: Mark POST Steve 0 minutes ago>
>>> Action.objects.filter(actor=a)
Error:
Traceback (most recent call last):
File "/.../lib/python3.5/site-packages/django/core/management/commands/shell.py", line 69, in handle
self.run_shell(shell=options['interface'])
File "/.../lib/python3.5/site-packages/django/core/management/commands/shell.py", line 61, in run_shell
raise ImportError
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/.../lib/python3.5/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/.../lib/python3.5/site-packages/django/db/models/query.py", line 790, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/.../lib/python3.5/site-packages/django/db/models/query.py", line 808, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/.../lib/python3.5/site-packages/django/db/models/sql/query.py", line 1243, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/.../lib/python3.5/site-packages/django/db/models/sql/query.py", line 1269, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/.../lib/python3.5/site-packages/django/db/models/sql/query.py", line 1149, in build_filter
lookups, parts, reffed_expression = self.solve_lookup_type(arg)
File "/.../lib/python3.5/site-packages/django/db/models/sql/query.py", line 1035, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/.../lib/python3.5/site-packages/django/db/models/sql/query.py", line 1316, in names_to_path
"adding a GenericRelation." % name
django.core.exceptions.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.
The output of my pip freeze
is:
app==0.0.1
coverage==4.2
dj-database-url==0.4.1
**Django==1.9.5**
**django-activity-stream==0.6.3**
django-anymail==0.5
django-bootstrap-breadcrumbs==0.8
django-bootstrap-datepicker==1.1.1
django-bootstrap3==7.1.0
django-bower==5.1.0
django-configurations==2.0
django-debug-toolbar==1.5
django-formtools==1.0
django-nose==1.4.4
django-postman==3.3.2
factory-boy==2.7.0
fake-factory==0.7.2
flake8==3.0.4
mccabe==0.5.2
nose==1.3.7
Pillow==3.3.1
psycopg2==2.6.2
pycodestyle==2.0.0
pyflakes==1.2.3
python-dateutil==2.6.0
PyYAML==3.12
requests==2.11.1
rollbar==0.13.6
six==1.10.0
sqlparse==0.2.1
whitenoise==3.2.1
Similar like issue 281
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
How to traverse a GenericForeignKey in Django?
filter (bar__name='bar x') FieldError: Field 'bar' does not generate an automatic reverse relation and therefore cannot be used for reverse ...
Read more >Filtering on action_object: Field 'action_object' does not generate an ...
Filtering on action_object: Field 'action_object' does not generate an automatic reverse relation and therefore cannot be used for reverse querying.
Read more >Action Filter does not filter Target Worksheet Including When ...
Issue. When a Filter Action has been created with the default "All Fields" selected for Target Filters, and the Filter Action is triggered,...
Read more >Chapter 5: Technology and Privacy Policy
This paper first describes how accountability and anonymity can be balanced to allow user control as much as possible, community norms when the...
Read more >Micro Focus ArcSight Command Center User's Guide
Micro Focus shall not be liable for technical or editorial errors or ... You can also use rules to automatically open or update...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This could work - Action.objects.filter(actor_object_id__in=user_queryset.values_list(‘id’, flat=True))
when I try to implement this logic to display the activity stream on the home/user dashboard page:
it throws the following error:
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.