How to allow 'filter' query parameter Django REST Framework JSON API?

I am using Django REST Framework with djangorestframework-jsonapi

When I query with filter[name]=THEOS DRF raise an error into my browser. I tried to query with this URL


THe other parameter from JSON API I can use it without any problem.

ValidationError at /api/space_objects/
[ErrorDetail(string='invalid filter[name]', code='invalid')]

And this is my DRF JSON API settings DRF JSON API Documentation

    'PAGE_SIZE': 10,
    'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
        # If you're performance testing, you will want to use the browseable API
        # without forms, as the forms can generate their own queries.
        # If performance testing, enable:
        # 'example.utils.BrowsableAPIRendererWithoutForms',
        # Otherwise, to play around with the browseable API, enable:
    'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
    'DEFAULT_SCHEMA_CLASS': 'rest_framework_json_api.schemas.openapi.AutoSchema',
    'SEARCH_PARAM': 'filter[search]',
    'TEST_REQUEST_DEFAULT_FORMAT': 'vnd.api+json'

My model

class SpaceObject(models.Model):
  class Meta:
    ordering = ['norad']

  norad = models.IntegerField(primary_key=True)
  object_type = models.CharField(max_length=200, null=True)
  name = models.CharField(max_length=200, null=True)
  period = models.FloatField(null=True)
  inclination = models.FloatField(null=True)
  apogee = models.FloatField(null=True)
  perigee = models.FloatField(null=True)
  rcs_size = models.CharField(max_length=200, null=True)
  tle_1 = models.CharField(max_length=200, null=True)
  tle_2 = models.CharField(max_length=200, null=True)
  last_updated = models.DateTimeField(max_length=6,

My serializer

class SpaceObjectSerializer(serializers.HyperlinkedModelSerializer):
  class Meta:
    model = SpaceObject
    fields = ['norad', 'object_type', 'name', 'period', 'inclination', 'apogee', 'perigee', 'rcs_size', 'tle_1', 'tle_2', 'last_updated']

I tried to run this but still got the problem

pip install djangorestframework-jsonapi['django-filter']

There is the way to fix the problem? I am tried to follow the documentation but not successful.

Any help is appreciated.

I hope you are well. First, you need to make sure that you have Django-Filter installed. Check this with the following command.

pip install 'django-filter'

Next, add the django-filter to INSTALLED_APPS.




Then, in your View class, you should set the fields and filter properties. Like the example below:

class SpaceObjectViewSet(viewsets.ModelViewSet):
  queryset = SpaceObject.objects.all()
  serializer_class = SpaceObjectSerializer
  permission_classes = [permissions.AllowAny]

  filterset_fields = {
         'name': ('exact', 'icontains', 'iexact', 'contains',),

and you call api for exact filter similar below:


and call for icontains similar below:


And remaining similar to icontains.

Back to Top