如何解决如何让视图知道另一个视图中的模型实例何时被保存
我正在使用一个不直接发送响应的 API(也许这是一个 api 标准)。一个粗略的例子:
def callbackview(request):
#This view will receive the actual required data from the api server,and save response to
#the db(there might be a better way to do this)
# Actually uses drf to parse/save the data
...
return Response(...)
def apisenderview(request):
#send the api request
resp=requests.get("https://api_url.com/api",{"callbackurl":"callbackview",...})
...
问题在于 resp
中的 apisenderview
收到的响应只是服务器队列详细信息。我认为我需要的是一种让 apisenderview
知道 API 服务器何时向 callbackview
发送响应的方法。我正在考虑的解决方案是:
...
def apisenderview(request):
#send the api request
resp=requests.get("https://api_url.com/api",{"callbackurl":"callbackview"})
callbackinstance=None:
while not callbackinstance:
callbackqs=callbackmodel.objects.filter(queue_id=resp.queue_id)
if callbackqs.exists():
callbackinstance=callbackqs.first()
#Continue with view operations
...
但是,上面的解决方案可能有太多的数据库调用(我还没有测试过)。我如何优化这个过程以确保最小的apisenderview
响应时间?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。