django-filter

Django - How to filter by date with Django Rest Framework?

依然范特西╮ 提交于 2021-02-17 21:35:29
问题 I have some model with a timestamp field: models.py class Event(models.Model): event_type = models.CharField( max_length=100, choices=EVENT_TYPE_CHOICES, verbose_name=_("Event Type") ) event_model = models.CharField( max_length=100, choices=EVENT_MODEL_CHOICES, verbose_name=_("Event Model") ) timestamp = models.DateTimeField(auto_now=True, verbose_name=_("Timestamp")) I'm then using Django-rest-framework to create an API endpoint for this class, with django-filter providing a filtering

How to rename (exposed in API) filter field name using django-filters?

那年仲夏 提交于 2021-02-07 06:29:08
问题 As the question states - I'm trying to rename the filter field name exposed in my API. I have the following models: class Championship(Model): ... class Group(Model): championship = ForeignKey(Championship, ...) class Match(Model): group = ForeignKey(Group, ...) I have exposed all of these models in REST API. I've defined filter_fields for the Match model: class MatchViewSet(ModelViewSet): filter_fields = ['group__championship'] ... This way, I can filter for specific championship's matches

Django : How to write Django Group by and where Condition?

放肆的年华 提交于 2021-01-29 13:24:40
问题 I have Django Model with five fields and I mention two fields in serializer class.I need to perform group by and where ClosingStock>0 condition. I have tried with this query but am not getting output. StoreClosingStock.objects.filter(CLOSING_STOCK__gte="0").values('ITEM_CODE','CLOSING_STOCK') I have implemented the same query in mysql its working fine .I want the same output in Django Views.py class StoreClosingViewset(viewsets.ModelViewSet): serializer_class = StoreClosingStockSerializer

django-filter button in template

最后都变了- 提交于 2020-12-13 03:38:18
问题 I'm using the django-filter package. My page displays all books. I have 5 genres. I want someone to be able to click a "scary" button, and have that filter my book list (user shouldn't have to also click "submit", just the genre button). But right now when I click a genre button, it doesn't filter. Unless I use a checkbox widget in my filters.py (commented out), check the box, and then click the genre button, but this looks ugly. Thanks in advance for the help! Filters.py class BookFilter

django-filter button in template

こ雲淡風輕ζ 提交于 2020-12-13 03:31:42
问题 I'm using the django-filter package. My page displays all books. I have 5 genres. I want someone to be able to click a "scary" button, and have that filter my book list (user shouldn't have to also click "submit", just the genre button). But right now when I click a genre button, it doesn't filter. Unless I use a checkbox widget in my filters.py (commented out), check the box, and then click the genre button, but this looks ugly. Thanks in advance for the help! Filters.py class BookFilter

different queryset based on permissions in Django Rest Framework

怎甘沉沦 提交于 2020-12-10 16:52:18
问题 I have seen this link, but I didn't find anything related to my question helping it being resolved. Imagine we have to create a blog, in which posts have two status: is_draft published ( published == !is_draft ) So, each user should see all of his/her posts, whether it is draft or not. In addition, Other users should see the published posts of rest of the users. I am using viewsets in django and I know that we should have different queryset based on the current user permissions but I don't

How can I use Date Picker with django-filter?

Deadly 提交于 2020-12-05 07:22:19
问题 I am trying to figure out how can I use datepicker with django-filter. I have tried a bunch of widgets but it's not working. Any suggestions will be appreciated! I want to use datepicker for the row_date search filter. filters.py from home2.models import AvailstaticCopy from django import forms import django_filters class DateInput(forms.DateInput): input_type = 'date' class AvailFilter(django_filters.FilterSet): class Meta: model = AvailstaticCopy widgets = {'row_date': DateInput(),} fields

How can I use Date Picker with django-filter?

对着背影说爱祢 提交于 2020-12-05 07:22:06
问题 I am trying to figure out how can I use datepicker with django-filter. I have tried a bunch of widgets but it's not working. Any suggestions will be appreciated! I want to use datepicker for the row_date search filter. filters.py from home2.models import AvailstaticCopy from django import forms import django_filters class DateInput(forms.DateInput): input_type = 'date' class AvailFilter(django_filters.FilterSet): class Meta: model = AvailstaticCopy widgets = {'row_date': DateInput(),} fields

How to filter product by Category wise in Django?

无人久伴 提交于 2020-08-10 19:12:30
问题 I am trying to filter according to the category but it's displaying all products on each category page, but I want filter according to the category page, please check my code and let me know how I can do it. here is my models.py file... class SubCategory(models.Model): subcat_name=models.CharField(max_length=225) subcat_slug=models.SlugField(max_length=225, unique=True) category = models.ForeignKey('Category', related_name='subcategoryies', on_delete=models.CASCADE, blank=True, null=True) and

how can I use pagination with django_filter

谁说我不能喝 提交于 2020-07-07 14:24:10
问题 I got a problem with pagination after using django_filter in my TemplateView. Before use django_filter, my pagination was working normally but now it show all the items in every page, I've been looking on the internet but I didn't find a good solution for this. how can I fix it? thanks my filter.py class SnippetFilter(django_filters.FilterSet): area = [] tecnology = Technology.objects.values('parent_area').distinct().order_by('parent_area_id') for a in tecnology: area.append(a['parent_area'])