有没有办法不在模板中显示我的模型?
我想知道在查看模板时是否可能不显示/加载产品模型。相反,我想在单击显示结果之前单击一个按钮,然后显示结果。
我的产品模型中有30,000多个记录,这就是为什么我不希望它们在查看模板时显示/加载,我知道Paginate_by ='100'方法存在,但是我发现过滤过滤更有用记录显示之前,
请注意:我已经有功能和类来过滤我的产品模型记录
class barcodeview(ListView):
template_name = "barcode/table.html"
paginate_by = '500'
model= Product
context_object_name = 'product'
# Queryset for filtering product model
def get_queryset(self):
queryset = Product.objects.barcode_filter(
filtr = self.request.GET.get("filtr", ''),
)
return queryset
I want to know if it is possible not to show/load my Product model when viewing a template. Instead, I want to display my model on click a button that filters the results before displaying them.
I have more than 30,000 records in my Product model and that is why I don't want them to show/load when viewing my template, I know that the paginate_by = '100' method exists, but I find it more useful to filter the records before displaying them
Note: I already have the function and class to filter my Product model records
class barcodeview(ListView):
template_name = "barcode/table.html"
paginate_by = '500'
model= Product
context_object_name = 'product'
# Queryset for filtering product model
def get_queryset(self):
queryset = Product.objects.barcode_filter(
filtr = self.request.GET.get("filtr", ''),
)
return queryset
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将过滤器表单放在模板中,仅在提交表单时仅输出模型。
模板:
查看:
您可以适应您的需求。过滤也可以在表单上进行:
这些不是唯一的方法,但是您明白了。
Put your filter form in your template and only output models when the form is submitted.
Template:
view:
You can adapt this to your needs. The filtering can also be done on the form:
Those aren't the only ways of doing it, but you got the point.