File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -83,17 +83,16 @@ def find_all(cls) -> list[Self]:
83
83
def get_recent (cls , shoppinglist_id : int , limit : int = 9 ) -> list [Self ]:
84
84
sq = db .session .query (ShoppinglistItems .item_id ).subquery ().select ()
85
85
sq2 = (
86
- db .session .query (func .max (cls .id ))
87
- .filter (cls .status == Status .DROPPED )
88
- .filter (cls .item_id .notin_ (sq ))
89
- .group_by (cls .item_id )
90
- .join (cls .item )
91
- .subquery ()
92
- .select ()
93
- )
94
- return (
95
- cls .query .filter (cls .shoppinglist_id == shoppinglist_id )
96
- .filter (cls .id .in_ (sq2 ))
97
- .order_by (cls .created_at .desc (), cls .item_id )
86
+ cls .query .filter (
87
+ cls .shoppinglist_id == shoppinglist_id ,
88
+ cls .status == Status .DROPPED ,
89
+ cls .item_id .notin_ (sq ),
90
+ )
91
+ .distinct (cls .item_id )
92
+ .order_by (cls .item_id , cls .created_at .desc ())
98
93
.limit (limit )
94
+ .subquery ()
99
95
)
96
+ alias = db .aliased (cls , sq2 )
97
+ q = db .session .query (alias ).order_by (alias .created_at .desc ())
98
+ return q .all ()
You can’t perform that action at this time.
0 commit comments