Search code examples
djangodjango-filter

django list_filter in html


enter image description here

How do i import this list_filter into my html? do you have any documentation that easy to follow and easy to understand? is it possible?

class ArticleListView(ListView):

    model = StudentsEnrollmentRecord
    s=StudentsEnrollmentRecord.objects.all()
    paginate_by = 50  # if pagination is desired
    searchable_fields = ["Student_Users", "id", "Section"]
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['now'] = timezone.now()
        return context 

Solution

  • You can use template tags to loop your object and populate your html:

    https://docs.djangoproject.com/en/3.0/ref/templates/builtins/

    To give you a kickstart:

    <ul>
    
    {% for filter in s %}
    
    <li>{{ filter.Student_Users }}</li>
    
    {% endfor %}
    
    </ul>
    

    This will basically create one <li> per each item in your queryset. Make sure that the required data is returned properly from your view via the context:

    context = {
            'queryset': s,    
        }
        return (context)