@@ -262,19 +262,21 @@ def _save_captions(self, commit=True, caption=None):
262
262
263
263
def _recreate_search_captions (self ):
264
264
search_captions = ""
265
- places365_captions = self .captions_json .get ("places365" , {})
266
265
267
- attributes = places365_captions . get ( "attributes" , [])
268
- search_captions += " " . join ( attributes ) + " "
266
+ if self . captions_json :
267
+ places365_captions = self . captions_json . get ( "places365" , {})
269
268
270
- categories = places365_captions .get ("categories " , [])
271
- search_captions += " " .join (categories ) + " "
269
+ attributes = places365_captions .get ("attributes " , [])
270
+ search_captions += " " .join (attributes ) + " "
272
271
273
- environment = places365_captions .get ("environment " , "" )
274
- search_captions += environment + " "
272
+ categories = places365_captions .get ("categories " , [] )
273
+ search_captions += " " . join ( categories ) + " "
275
274
276
- user_caption = self .captions_json .get ("user_caption" , "" )
277
- search_captions += user_caption + " "
275
+ environment = places365_captions .get ("environment" , "" )
276
+ search_captions += environment + " "
277
+
278
+ user_caption = self .captions_json .get ("user_caption" , "" )
279
+ search_captions += user_caption + " "
278
280
279
281
for face in api .models .face .Face .objects .filter (photo = self ).all ():
280
282
search_captions += face .person .name + " "
@@ -287,6 +289,7 @@ def _recreate_search_captions(self):
287
289
288
290
if self .camera :
289
291
search_captions += self .camera + " "
292
+
290
293
if self .lens :
291
294
search_captions += self .lens + " "
292
295
@@ -310,7 +313,7 @@ def _generate_captions(self, commit):
310
313
311
314
self .captions_json ["places365" ] = res_places365
312
315
self ._recreate_search_captions ()
313
- # Remove from all places365_attribute and places365_category albums
316
+
314
317
for album_thing in api .models .album_thing .AlbumThing .objects .filter (
315
318
Q (photos__in = [self .image_hash ])
316
319
& (
@@ -321,6 +324,7 @@ def _generate_captions(self, commit):
321
324
).all ():
322
325
album_thing .photos .remove (self )
323
326
album_thing .save ()
327
+
324
328
if "attributes" in res_places365 :
325
329
for attribute in res_places365 ["attributes" ]:
326
330
album_thing = api .models .album_thing .get_album_thing (
@@ -330,6 +334,7 @@ def _generate_captions(self, commit):
330
334
)
331
335
album_thing .photos .add (self )
332
336
album_thing .save ()
337
+
333
338
if "categories" in res_places365 :
334
339
for category in res_places365 ["categories" ]:
335
340
album_thing = api .models .album_thing .get_album_thing (
0 commit comments