Right, kindly heed to the problem as early as possible, The GitHub link is provided below.
On Fri, 25 Jun 2021 at 19:34, Symaxx <bukhosizimcode@gmail.com> wrote:
This is easier to work with on GitHub, do you have a GitHub account?You can raise an issue then share the link here 🙂--On Fri, 25 Jun 2021, 3:04 PM Aritra Ray, <aritra805@gmail.com> wrote:Hi,--This is my second request regarding the same issue. I've been building a Django E-commerce website and I'm facing problems filtering the product according to price. I used django-filter to filter category and size. Please suggest a solution for price in the following manner: Latest products, Lowest to Highest and Highest to Lowest. I've made some progress in the template without using django-filter. Kindly help me tie it up with the backend.Do let me know if anything else is needed.Thanks for your help in advanceRegards,Aritra#products-html<!--Filter--><div class="row"><div class="container"><form method="get"style="width:20%">{{filter.form|crispy}}<div class="row"><label>Select sorting criteria</label><div class="control"><div class="select"><select name="sorting"><option value="-date_added"{% if sorting == '-date_added' %}selected{% endif %}>Latest collection</option><option value="price"{% if sorting == 'price' %} selected {% endif %}>Lowest to Highest</option><option value="-price"{% if sorting == '-price' %} selected {% endif %}>Highest to Lowest</option></select></div></div></div><button type="submit" class="btn btn-warning btn-sm"><span class="glyphicon glyphicon-search"></span> Search</button></form></div></div>#views.pyclass Product(ListView):model = Itemspaginate_by = 6template_name = 'products.html'ordering = ["-id"]def get_queryset(self):queryset = super().get_queryset()filter = ProductFilter(self.request.GET, queryset)return filter.qsdef get_context_data(self, **kwargs):context = super().get_context_data(**kwargs)queryset = self.get_queryset()filter = ProductFilter(self.request.GET, queryset)context["filter"] = filterreturn context# filters.pyimport django_filtersfrom .models import Itemsclass ProductFilter(django_filters.FilterSet):class Meta:model = Itemsfields = ['size', 'category']
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecadt5eYOdDX3sL46kbscLfbhwAzEcvwUpM9TF_s%2B9YhBGVQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANPYDAtyWhqy%3DGM%3DEGpwVrUFDrTuctmgpN4xPcrLyKYgOv23cg%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecaduYnX1yYU-f1B2rOKZjX4_XnU-%2BVDGVPZan4DikY_e19A%40mail.gmail.com.
No comments:
Post a Comment