django - 按 django 选择过滤?
问题描述
我想按类别过滤。但是,它不起作用。
views.py
def BytovyeTexnikiPylesosy(request):
products = BytovyeTexniki.objects.filter(category='pylesosy')
context = {
'products': products,
}
return render(request, 'store/product.html',context)
models.py
TEXNIKI = (
('pylesosy','Пылесосы'),
('stiralki','Стиральные машины'),
('xolodilniki','Холодильники'),
)
lass BytovyeTexniki(models.Model):
name = models.CharField(max_length=200)
category = models.CharField(max_length=300, choices=TEXNIKI)
price = models.FloatField()
image = models.ImageField(null=True, blank=True)
def __str__(self):
return self.name
@property
def imageURL(self):
try:
url = self.image.url
except:
url = ''
return url
我正在尝试使用此代码。但是,它不起作用。我想按类别过滤。请帮忙?
解决方案
推荐阅读
- mongodb - 如何检查一个值是否存在于整个 MongoDB 集合中的任何位置?
- swift - 如何用闭包简化这个 Swift 代码
- javascript - 通过使用 source 属性来选择图像元素来查找它
- python-3.x - 在 CANbus 上接收消息总是返回与 python-can 相同的值
- visual-studio-2019 - 使用 IntelliTest 为我的代码生成单元测试
- c# - 尝试读取 OracleDataReader 时如何修复“关闭对象上的无效操作”异常
- azure - 刷新令牌被拒绝和空响应以查看令牌存储中的令牌
- flutter - Visual Studio Code 在 Flutter 中添加“prefix0”
- python-3.x - 成功安装 python-weka-wrapper 后无法使用 weka.core 模块“没有名为'weka.core'的模块”
- imshow - cv2.imshow() 图像较小时无法正常工作