django_filters.FilterSet with Or Operator
<p>i'd like to try an <strong>OR statement</strong> with django_filters.FilterSet, to create a "filter only field" (ie: doesn't exist in the model). This field should check if the filter value match one of the models "real field" (two of them)</p>

<p>Here is my Model:</p>

<pre><code>class Project(models.Model):
    id          = models.BigIntegerField(primary_key=True)
    name        = models.CharField(max_length=255) 
    cat         = models.ForeignKey(Category, related_name='projects', db_index=True, default=None, null=True)
    cat_main    = models.IntegerField(db_index=True, null=True)
    category_id = models.IntegerField(db_index=True, null=True)
    country     = models.CharField(max_length=16, null=True)
    added       = models.DateTimeField(auto_now_add=True)
    modified    = models.DateTimeField(auto_now=True)
</code></pre>

<p>Here is the code i tried to achieve this:</p>

<pre><code>from django.db.models import Q

class ProjectCatFilter(django_filters.FilterSet):
    category = django_filters.MethodFilter(name='category', action='category_or_filter')
    class Meta:
        model = Project
        fields = ['cat_main', 'category_id']

    def category_or_filter(self, queryset, value):
        return queryset.filter(
            Q(category_id=value) | Q(cat_main=value)
        )
</code></pre>

<p>And here is the call that should return me either Project where "category" match "cat_main" or "category_id"</p>

<pre><code>from server.ks.models import Project
projects = Project.objects.filter(category=1)
for p in projects:
    print p.name, p.id, p.cat_main, p.category_id
</code></pre>

<p>but i get this error:</p>

<blockquote>
  <p>django.core.exceptions.FieldError: Cannot resolve keyword 'category' into field. Choices are: name, cat, cat_id, cat_main, category_id, country, added, modified</p>
</blockquote>

<p>Then what is the correct/best way for Project.objects.filter(category=1) to return projects that match category_id OR main_cat fields (with FilterSet or not)?</p>