How to filter in a django mptt-model using django-filters

Advertisements I have models.py from mptt.models import MPTTModel, TreeForeignKey class Category(MPTTModel): name = models.CharField(max_length = 255, null = False, blank = False) parent = TreeForeignKey(‘self’, on_delete = models.CASCADE, blank = False, null = True, related_name = ‘children’) # other fields class Product(models.Model): category = models.ForeignKey(Category, on_delete = models.SET_NULL, null = True, blank = True, related_name… Read More How to filter in a django mptt-model using django-filters

Unable to filter using django-filters

Advertisements I have a models.py which looks like this class Product(models.Model): name = models.CharField(max_length = 255, unique = True, null = False, blank = False) brand = models.ForeignKey(Brand, on_delete = models.SET_NULL, null = True, blank = True, related_name = ‘products’) class Brand(models.Model): name = models.CharField(max_length = 255, unique = True, null = False, blank =… Read More Unable to filter using django-filters

3 django model filterset with django-filter

Advertisements I have 3 different django models and I want to filter using django-filter. The ORM query I wrote below works without any problems. but how can i do this with django-filter (filters.FilterSet) ? Employee.objects.filter(companyrecord__company__cname__icontains="ompanyname") THIS IS WORKS it is work for me in ORM. But how can i do this in filter set. I… Read More 3 django model filterset with django-filter

Django – How to add "or" condition to queryset.filter in custom filter

Advertisements i want to make a search filter which searches in multiple fields with multiple conditions, using only one search field. I have this filters.py file: import django_filters from .models import Product class ProductFilter(django_filters.FilterSet): q = django_filters.CharFilter(method=’search_filter’, label=’Cerca’) class Meta: model = Product fields = [‘q’] def search_filter(self, queryset, name, value): return queryset.filter(name__icontains=value, sku__iexact=value) but… Read More Django – How to add "or" condition to queryset.filter in custom filter

Django filtering if an object has the specified value or is either isnull

Advertisements I have a view that returns all the users that are either working in or are students in the school that the request.user owns, in my model’s I have two fields works and learns that are foreignkey fields referencing the school object, when filtering the users to match the school that the request.user owns,… Read More Django filtering if an object has the specified value or is either isnull

Django: Django_filters in a class-based views

Advertisements I ask you if you know how put this filters : class CoursesFilters(django_filters.FilterSet): class Meta: model = Courses exclude = (‘description’) in this class view : class CoursesList(ListView): model = Courses template_name = ‘courses_list.html’ I used to build my applications using function-based views, and this is my first time use class-based views. Any idea?… Read More Django: Django_filters in a class-based views

custom filtering in django rest framework

Advertisements I am trying to implement custom filtering in my code and went through the documentation. But I couldnt understand the following snippets from the docs. class UserFilter(django_filters.FilterSet): class Meta: model = User fields = [‘username’, ‘last_login’] # or class UserFilter(django_filters.FilterSet): class Meta: model = User fields = { ‘username’: [‘exact’, ‘contains’], ‘last_login’: [‘exact’, ‘year__gt’],… Read More custom filtering in django rest framework