File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -127,11 +127,11 @@ def get(self, image_id):
127
127
128
128
categories = CategoryModel .objects (deleted = False ).in_bulk (dataset .categories ).items ()
129
129
130
+
130
131
# Get next and previous image
131
- images = list (ImageModel .objects (dataset_id = dataset .id , deleted = False ).order_by ('file_name' ).all ())
132
- image_index = images .index (image )
133
- image_previous = None if image_index - 1 < 0 else images [image_index - 1 ].id
134
- image_next = None if image_index + 1 == len (images ) else images [image_index + 1 ].id
132
+ images = ImageModel .objects (dataset_id = dataset .id , deleted = False )
133
+ pre = images .filter (file_name__lt = image .file_name ).order_by ('-file_name' ).first ()
134
+ nex = images .filter (file_name__gt = image .file_name ).order_by ('file_name' ).first ()
135
135
136
136
preferences = {}
137
137
if not Config .LOGIN_DISABLED :
@@ -149,8 +149,8 @@ def get(self, image_id):
149
149
}
150
150
}
151
151
152
- data ['image' ]['previous' ] = image_previous
153
- data ['image' ]['next' ] = image_next
152
+ data ['image' ]['previous' ] = pre . id if pre else None
153
+ data ['image' ]['next' ] = nex . id if nex else None
154
154
155
155
for category in categories :
156
156
category = query_util .fix_ids (category [1 ])
You can’t perform that action at this time.
0 commit comments