如何在Django_过滤器和JSONfield中使用modelmultipleechoicefilter

2024-09-29 23:20:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在我的模型中使用django_filterswithJSONfield,但我不能这样做。在

如果使用CharFields我可以得到当前的结果,但我需要对请求进行可能的工作。
当我使用ModelMultipleChoiceFilter时,我从filter中得到了所有的变体,但是过滤并没有发生。在

Models.py

class Product(models.Model):
    name = models.CharField(max_length=120)
    properties = JSONField(default=dict, blank=True, null=True, db_index=True)

Filters.py

^{pr2}$

This is Item

{
    "id": 10,
    "name": "Test_3",
    "properties": {
        "color": "Black",
        "invertor technology": false,
        "service area, m²": 24
    },
},

选择黑色,
我有一个错误:选择正确的选项。黑色在值中无效。


Tags: djangonamepy模型truemodelsproperties变体

热门问题