django - 如何按名称和最高时间戳获取对象
问题描述
我想获取属于 external_id=1 并具有最高时间戳的事务。
我试过这个
max_rating = Transaction.objects.aggregate(organisation_id_from_partner=organisation_id, highest_timestamp=Max('timestamp'))
但我明白了TypeError: QuerySet.aggregate() received non-expression(s): 1.
解决方案
在聚合内部,您只能编写聚合函数。尝试这个
max_rating = Transaction.objects.filter(organisation_id_from_partner=organisation_id).order_by('-timestamp').first()
推荐阅读
- android - 如何使用来自服务器(Android)的数据创建缩略图照片库?
- c - 开罗以错误的方向呈现阿拉伯文本
- xcode - 在带有 Cocoapods 的 XCode 中找不到 FBSDKCoreKit.modulemap
- java - 返回或返回实例变量的小数
- laravel - Laravel 缺少参数来更新控制器中的表单
- javascript - 如何在 React 中创建带有 URL 的页面
- apache-kafka - 卡夫卡:节点发送了一个无效的完整获取响应,带有额外的
- python - 如何将“脏”csv文件导入熊猫并绘图?
- nest-device-access - 授权设备访问时没有刷新令牌
- typescript - 打字稿错误:“”仅指一种类型,但在此处用作命名空间