【问题标题】:Django front-end filter for users to filter model objectsdjango前端过滤器供用户过滤模型对象
【发布时间】:2016-05-17 08:20:21
【问题描述】:

我正在尝试在我的 Django 网站上创建一个前端过滤器和搜索系统,如下所示: http://www.habitat.co.uk/sofas-armchairs/sofas-categories/leather-sofas/hyde-leather/shopby/brown/price-655-1500

以下是我想实现的功能:

  • 过滤器在用户搜索关键字后仍然有效,过滤器只会继续缩小搜索范围
  • 一个列出的表单,其中包含供用户点击的所有类别过滤器
  • 当用户点击上面列出的链接等过滤器时,根据过滤器更改的网址

我的 Django 模型只是一个像这样的简单模型:

class Product(models.Model):
    seller = models.ForeignKey(SellerAccount)
    media = models.ImageField(blank=True, 
        null=True, 
        upload_to=download_media_location,
        storage=FileSystemStorage(location=settings.PROTECTED_ROOT))
    title = models.CharField(max_length=30) 
    slug = models.SlugField(blank=True, unique=True)
    description = models.TextField()
    price = models.DecimalField(max_digits=100, decimal_places=2, default=9.99, null=True,)
    sale_active = models.BooleanField(default=False)
    sale_price = models.DecimalField(max_digits=100,
         decimal_places=2, default=6.99, null=True, blank=True) 

与其他领域......

我的问题是,构建我想要的搜索和过滤系统的最佳方法是什么?我可以使用现有的 django 库吗?

【问题讨论】:

  • 你在看 django-haystack 吗?
  • 我没有,但我现在会。

标签: django filter model frontend


【解决方案1】:

您需要的一切都可以使用django-filter 制作。更多信息:http://django-filter.readthedocs.io/

【讨论】:

    猜你喜欢
    • 2013-03-16
    • 2018-08-05
    • 2020-07-02
    • 2012-03-13
    • 1970-01-01
    • 2019-12-27
    • 2014-08-22
    相关资源
    最近更新 更多