How to filter multiple fields with list of objects
<p>I want to build an webapp like <a href="http://www.quora.com/">Quora</a> or <a href="https://medium.com">Medium</a>, where a user can follow users or some topics. </p>

<p>eg: userA is following (userB, userC, tag-Health, tag-Finance).</p>

<p>These are the models:</p>

<pre><code>class Relationship(models.Model):
    user = AutoOneToOneField('auth.user')
    follows_user = models.ManyToManyField('Relationship', related_name='followed_by')
    follows_tag = models.ManyToManyField(Tag)

class Activity(models.Model):
    actor_type = models.ForeignKey(ContentType, related_name='actor_type_activities')
    actor_id = models.PositiveIntegerField()
    actor = GenericForeignKey('actor_type', 'actor_id')
    verb = models.CharField(max_length=10)
    target_type = models.ForeignKey(ContentType, related_name='target_type_activities')
    target_id = models.PositiveIntegerField()
    target = GenericForeignKey('target_type', 'target_id')
    tags = models.ManyToManyField(Tag)
</code></pre>

<p>Now, this would give the following list:</p>

<pre><code>following_user = userA.relationship.follows_user.all()
following_user
[&lt;Relationship: userB&gt;, &lt;Relationship: userC&gt;]
following_tag = userA.relationship.follows_tag.all()
following_tag
[&lt;Tag: tag-job&gt;, &lt;Tag: tag-finance&gt;]
</code></pre>

<p>To filter I tried this way:</p>

<pre><code>Activity.objects.filter(Q(actor__in=following_user) | Q(tags__in=following_tag))
</code></pre>

<p>But since actor is a GenericForeignKey I am getting an error:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>How can I filter the activities that will be unique, with the list of users and list of tags that the user is following? To be specific, how will I filter GenericForeignKey with the list of the objects to get the activities of the following users.</p>