filtering objects based on boolean field state

I’m working on a project where a form is filled out. And in that form you have the is_active fields. If the user selects True, it means the account is active and if it is False, it means it is no longer active, and the user can no longer see it. Through the filters I’m… Read More filtering objects based on boolean field state

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

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 return… 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

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, I… Read More Django filtering if an object has the specified value or is either isnull

Django: Django_filters in a class-based views

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? >Solution… Read More Django: Django_filters in a class-based views

custom filtering in django rest framework

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