如何将Django筛选器结果分配给verbose_name_plural变量?

时间:2019-05-23 00:49:21

标签: python django

如何将Django过滤器结果分配给Django中的verbose_name_plural变量#?

研究了如何在Django中使用用户输入并在python中访问类变量来构造动态查询


从库存中

.filters导入InventoryFilter

inventory = InventoriFilter()

obj = {
    "inventory":[inventory.inventori],
}

inventoris = Inventory.objects.filter(*obj['inventory'])

context={
    'inventoris': inventoris,
}

来自inventory.filters文件

class InventoriFilter(django_filters.FilterSet):
    inventori = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Inventory
        fields = ['id', 'inventori', 'price', 'quantity',]

来自models.py

class Inventori(models.Model):
    inventori = models.CharField(max_length=50)

输出:InventoriFilter没有属性“ inventori”

0 个答案:

没有答案