broken use case of django-filters + djanorestframework's autogen docs?

13 views
Skip to first unread message

aa...@skilljar.com

unread,
Apr 5, 2019, 3:10:44 PM4/5/19
to django-filter
Pardon the cross-post, but it seems I may have run into a limitation of Django-Filters + DRF's autodocs, 
would appreciate any input or confirmation.

https://stackoverflow.com/questions/55528780/conditional-filtersets-in-drf-3-7-autogen-docs-can-i-add-a-queryparam-filter-fo#55529054

I have a working FilterSet that lets me filter my results via a query parameter, e.g. http://localhost:9000/mymodel?name=FooOnly

This is working just fine.


class MyNameFilter(FilterSet):
    name = CharFilter(field_name='name', help_text='Filter by name')

    class Meta:
        model = MyModel
        fields = ('name',)


class MyModel(...):
    ...
    filter_backends = (DjangoFilterBackend,)
    filter_class = MyNameFilter


But when I render the built-in auto-generated docs for my API, I am seeing this query parameter documented for all methods in my route, e.g. GETPUTPATCH, etc.


I tried writing a custom DjangoFilterBackend -- and while this ensures the functionality of the API (e.g. only GETs would process the filtering queryparam), it doesn't prevent the DRF autodocs from including the queryparam where it shouldn't be.


Thanks. 


Carlton Gibson

unread,
Apr 5, 2019, 3:28:53 PM4/5/19
to django...@googlegroups.com
You’ll need to subclass the AutoSchema inspector and override get_filter_fields() to adjust by method. 

--
You received this message because you are subscribed to the Google Groups "django-filter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-filte...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

aa...@skilljar.com

unread,
Apr 6, 2019, 4:10:39 PM4/6/19
to django-filter
Thank you for the very helpful directional pointer.

I added my full solution to https://stackoverflow.com/a/55553040/39529
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages