Coder Social home page Coder Social logo

neithan / django-filters-facet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caktus/django-filters-facet

0.0 0.0 0.0 5.12 MB

A django-filter extension to refine search results using faceted navigation functionality.

Home Page: https://facets.caktus-built.com

License: MIT License

Shell 2.72% JavaScript 0.52% Python 67.60% CSS 0.06% HTML 22.46% Dockerfile 6.63%

django-filters-facet's Introduction

django-filters-facet

django-filters-facet is a django-filter extension to refine search results using faceted navigation functionality.

test

A live demo is available on https://facets.caktus-built.com/films/.

For example, the sidebar interface when searching a library's catalog:

Example facet screenshot

Installation

Install using pip:

# Until we release on pypi...
pip install git+https://github.com/caktus/django-filters-facet.git@main#egg=django-filters-facet

Usage

django-filters-facet provides a FacetedFilterSet class that calls a configure_facets() method that can be used for configuring facets. For example, if you had a Film model you could have a filterset for it with the code:

# example-facets/films/filters.py
from django_filters_facet import Facet, FacetedFilterSet

from .models import Film


class FilmFilterSet(FacetedFilterSet):

    class Meta:
        model = Film
        fields = ["type", "release_year", "rating", "listed_in"]

    def configure_facets(self):
        self.filters["type"].facet = Facet()
        self.filters["rating"].facet = Facet()

And then in your view, you pass the QuerySet through the FilmFilterSet and add it to the template context:

# example-facets/films/views.py
from django.views.generic.list import ListView

from .filters import FilmFilterSet
from .models import Film


class FilmListView(ListView):

    model = Film

    def get_queryset(self):
        qs = super().get_queryset()
        self.filter_set = FilmFilterSet(self.request.GET, queryset=qs)
        return self.filter_set.qs

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["filter"] = self.filter_set
        return context

And finally, show the facets in your template:

{% load search_tags %}

<aside>{% show_facets filter %}</aside>

Contributing

If you think you've found a bug or are interested in contributing to this project, check out django-filters-facet on Github.

Development sponsored by Caktus Consulting Group, LLC.

Example project

See example-facets/README.md documents how to setup the app, django_filters_facet, and the example-facets Django project for development.

Unit tests

Run tests:

poetry run pytest --cov-report=html

django-filters-facet's People

Contributors

copelco avatar jcjudkins avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.