[英]Filter Products by Distribution Center Quantity Channel advisor REST API
我正在研究django項目,在該項目中,我使用文件導出功能從Channel Advisor平台獲取產品。 我正在使用過濾器 ' $filter=ProfileID eq 和 TotalQuantity gt 0' 。
https://developer.channeladvisor.com/working-with-products/product-exports
我想根據目錄列表頁面中的“可用倉庫數量”字段中的值而不是“總數量”來查詢產品。 或按配送中心數量過濾,例如:“鳳凰”配送中心庫存大於 0 的產品。
謝謝你。
我認為最簡單的方法是覆蓋ModelViewSet
的get_queryset
方法:
視圖.py
def BaseAPIView(...):
''' base view for other views to inherit '''
def get_queryset(self):
queryset = self.queryset
# get filter request from client:
filter_string = self.request.query_params.get('filter')
# apply filters if they are passed in:
if filters:
filter_dictionary = json.loads(filter_string)
queryset = queryset.filter(**filter_dictionary)
return queryset
請求 url 現在看起來像: my_website.com/api/products?filter={"name":"book"}
或更准確地說: my_website.com/api/products?filter=%7B%22name%22:%22book%22%7D
:%22book%22%7D
可以像這樣構建:
腳本.js
// using ajax as an example:
var filter = JSON.stringify({
"name" : "book"
});
$.ajax({
"url" : "my_website.com/api/products?filter=" + filter,
"type" : "GET",
...
});
一些優點:
exclude
做同樣的事情一些缺點:
總的來說,這種方法對我來說比那里的任何軟件包都有用得多。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.