我在数据库中有很多重复项。为了只提供一个(而不是重复项),我正在尝试使用set,但它也返回了重复项。
all_orders = Order.query.filter_by(account_id=account.id).all()
orders = set(all_orders)
Run Code Online (Sandbox Code Playgroud)
{377, 348, 353, 377, 354, 377, 356, 377, 357, 377, 359, 378, 358, 378, 361, 378, 357, 378, 364, 378, 363, 378, 378, 362, 364, 379, 355, 379, 366, 379, 367, 379, 368, 379, 358, 379, 369, 379, 358, 379, 369, 379, 337, 370, 379, 338, 370, 379, 339, 343, 371, 379, 347, 371, 379, 372, 379, 372, 379, 373, 379, 373, 379, 374, 379, 374, 379, 375, 379, 375, 379, 376, 379, 376, 379, 376, 379, 376, 379, 376, 379, 377, 379, 377, 379, 377, 379, 377, 379, 377, 380, 377, 381, 377, 377, 377, 377}
Run Code Online (Sandbox Code Playgroud)
编辑
我正在接收 webhook 数据,并且 webhook 多次触发。我能够将 sale_id 设置为唯一的,防止进一步发生重复数据。
使用.distinct()sql alchemy 查询中的方法来获取类似集合的列表。
...
timestamp = calendar.timegm(created.utctimetuple()) # Used to convert time for Intercom
orders = Order.query.filter_by(account_id=account.id).distinct()
print(orders)
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6764 次 |
| 最近记录: |