Where is the filter filter for the django filter located?

The documentation shows

We have several fields, and we want our users to filter based on price or release_date. We create a FilterSet for this:

import django_filters

class ProductFilter(django_filters.FilterSet):
    class Meta:
        model = Product
        fields = ['price', 'release_date']

Where is this code placed to create a FilterSet? Is it in models or presentations? Thank.

+4
source share
1 answer

Anywhere, I mean models.py, views.py or even a new file called filters.py. Because you will use this filter in views.py so that you can import filters everywhere in your project. For me, I think the filters.py file in the application is the best place.

So in your view.py import the filters like this:

from .filters import ProductFilter
+6

Source: https://habr.com/ru/post/1544602/


All Articles