问题
I would like to filter Actions for particular queryset.
To this moment I was grabbing data by generating a model stream on desired model.
model_stream(FillingSystem)
I would like to extend this functionality and have something like this
model_stream(FillingSystem.objects.filter(client__slug='my-slug'))
or
model_stream(FillingSystem.objects.filter(client=Client.objects.get(slug='my-slug')))
this model looks like this:
class FillingSystem(models.Model):
client = models.ForeignKey('accounts.Client')
How do I filter a stream by related slug field?
回答1:
It seems you can just pass your filters as **kwargs
:
model_stream(FillingSystem, filling_system__client__slug='my-slug')
where target
is a GenericForeignKey
to your content (feel free to choose from the others).
You may have to declare a reverse relation to the Action
model:
from django.contrib.contenttypes.fields import GenericRelation
from actstream.models import Action
class FillingSystem(models.Model):
client = models.ForeignKey('accounts.Client')
stream_actions = GenericRelation(
Action,
content_type_field='target_content_type'
object_id_field='target_object_id'
related_query_name='filling_system')
来源:https://stackoverflow.com/questions/34708719/django-activity-stream-filter-actions-by-foreignkey-in-target-model