How to rename (exposed in API) filter field name using django-filters?
<p>As the question states - I'm trying to rename the filter field name exposed in my API.</p>

<p>I have the following models:</p>

<pre><code>class Championship(Model):
    ...

class Group(Model):
    championship = ForeignKey(Championship, ...)

class Match(Model):
    group = ForeignKey(Group, ...)
</code></pre>

<p>I have exposed all of these models in REST API. I've defined <code>filter_fields</code> for the <code>Match</code> model:</p>

<pre><code>class MatchViewSet(ModelViewSet):
    filter_fields = ['group__championship']
    ...
</code></pre>

<p>This way, I can filter for specific championship's matches (tested and working):</p>

<blockquote>
  <p>curl /api/matches/?group__championship=1</p>
</blockquote>

<p>Is is possible to use some kind of alias for the exposed filter so I can use the following:</p>

<blockquote>
  <p>curl /api/matches/?championship=1</p>
</blockquote>

<p>where <code>championship</code> in this case will be an alias for <code>group__championship</code>?</p>

<p><code>pip freeze</code> returns:</p>

<pre><code>django-filter==0.15.2
(...)
</code></pre>

<p>I've also tried implementing custom <code>FilterSet</code> with <code>ModelChoiceFilter</code> and custom lookup method:</p>

<pre><code>class MatchFilterSet(FilterSet):
    championship = ModelChoiceFilter(method='filter_championship')

    def filter_championship(self, queryset, name, value):
        return queryset.filter(group__championship=value)

    class Meta:
        model = Match
        fields = ['championship']
</code></pre>

<p>With view:</p>

<pre><code>class MatchViewSet(ModelViewSet):
    filter = MatchFilterSet
    (...)
</code></pre>

<p>But with no luck. The <code>filter_championship</code> method was even never called.</p>

<p>You need to provide model field as name in django_filters with field type. I am considering you are trying to filter by championship id.</p>

<pre><code>class MatchFilterSet(FilterSet):
    championship = django_filters.NumberFilter(name='group__championship_id')

    class Meta:
        model = Match
        fields = ['championship']
</code></pre>

python django rest django-filter