更新时间:2023-11-26 19:26:28
似乎你可以只是将您的过滤器作为 ** kwargs
:
model_stream(FillingSystem,filling_system__client__slug ='my-slug')
其中目标
是一个 GenericForeignKey
到您的内容(随意选择来自其他人)。
您可能需要声明与 Action
模型的反向关系:
从actstream.models import导入GenericRelation
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')
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?
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')