How to Use django_filters in Your Django Project​

Areeba Seher | Lets Code More
Python in Plain English
4 min readMay 31, 2024

Photo by AltumCode on Unsplash

For filtering and transforming data in Django, there is a powerful and user-friendly package called django-filters. When working with huge datasets or complex data structures, this module offers a convenient and adaptable approach to filter and manipulate data in your Django applications.

If you’re not a paid member, feel free to enjoy the free article here.

Installation.

django-filters can be easily installed by pip

pip install django-filter

Then add ‘django_filters' to your INSTALLED_APPS in settings.py.

# settings.py

INSTALLED_APPS = [
.......
'django_filters'
]

Getting Started

Let’s start with our models. We have a simple Product model.

# models.py

from django.db import models

class Product(models.Model):
title = models.CharField(max_length=150)
price = models.DecimalField(max_digits=5, decimal_places=2)
featured = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
update_at = models.DateTimeField(auto_now=True)

def __str__(self):
return self.title

The filter.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

I'm Areeba Seher, I share engaging insights on programming, freelancing, & strategies for achieving success. https://www.linkedin.com/in/areeba-seher-699791172/