Search code examples
djangotastypie

Tastypie model field named "format"


I'm using tastypie and I have a unique situation. My model has a field named "format" so when I try to make a call to the related API and pass format=json, I get this error:

The 'format' field does not allow filtering.

Other than renaming my model field, is there another workaround for this?


Solution

  • Looks like 'format' is hard-coded in tastypie.utils.mime.determine_format(). You could override Resource.determine_format:

    class MyResource(ModelResource):
           def determine_format(self, request):
            """
            Used to determine the desired format.
    
            Largely relies on ``tastypie.utils.mime.determine_format`` but here
            as a point of extension.
            """
    
            # Determine your format and return it.
            # This is the default implementation.
            return determine_format(request, self._meta.serializer, default_format=self._meta.default_format)