Search code examples
pythondjangotastypieswagger

Specifying parameters in tastypie-swagger


I am using Tastypie as an API framework for Django for non-ORM data source. I have used django-tastypie-swagger. It has worked fine for everything but I haven't figured out how to display the parameters for get/post request for obj_get_list. Currently two default values are shown as shown below:

Screenshot


Solution

  • The parameters are retrieved from filtering specified in the Meta of class inherited from Resource. There seems to be a small bug in django-tastypie-swagger as it doesn't recognize filters if it is specified as tuples. We need to specify filtering as lists. For e.g.

    class VideoById(Resource):
        class Meta:
            filtering = {
                "filter1": ['exact', ],
                "filter2": ['exact', ],
            }
    

    The above mentioned code works. But the following won't:

    class VideoById(Resource):
        class Meta:
            filtering = {
                    "filter1": ('exact', ),
                    "filter2": ('exact', ),
                }