Django REST框架:由于大型相关表,浏览速度较慢的UI [英] Django REST Framework: slow browsable UI because of large related table

查看:189
本文介绍了Django REST框架:由于大型相关表,浏览速度较慢的UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的API中有一个模型,它具有一个具有数万条记录的表的外键。当浏览到可浏览的UI中的该模型的详细信息页面时,页面加载将永远存在,因为它正在尝试使用PUT命令的HTML表单的成千上万条目填充外键下拉列表。



有没有办法解决这个问题?我认为我最好的解决方案是让可浏览的UI不显示这个字段,从而防止缓慢的负载。人们仍然可以通过实际的PUT api请求直接更新该字段。



谢谢。

解决方案

看一下使用自动完成的小部件,或者下拉到使用愚蠢的文本框部件。



自动完成文档在这里: http://www.django-rest-framework.org/topics/browsable-api/#autocomplete


I have a model in my API that has a foreign key to a table with tens of thousands of records. When I browse to that model's detail page in the browsable UI, the page load takes forever because it is trying to populate the foreign key dropdown with tens of thousands of entries for the HTML form for the PUT command.

Is there anyway to work around this? I think my best solution would be to have the browsable UI not show this field and thus prevent the slow load. People can still update the field by an actual PUT api request directly.

Thanks.

解决方案

Take a look at using an autocomplete widget, or drop down to using a dumb textfield widget.

Autocompletion docs here: http://www.django-rest-framework.org/topics/browsable-api/#autocomplete

这篇关于Django REST框架:由于大型相关表,浏览速度较慢的UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆