Forráskód Böngészése

[books] Handle authors from Google

Colin Powell 3 hónapja
szülő
commit
c51c75b6a6
1 módosított fájl, 9 hozzáadás és 0 törlés
  1. 9 0
      vrobbler/apps/books/models.py

+ 9 - 0
vrobbler/apps/books/models.py

@@ -165,12 +165,21 @@ class Book(LongPlayScrobblableMixin):
         ).as_dict_with_authors_cover_and_genres()
 
         if created or overwrite:
+            author_list = []
+            if authors:
+                for author_str in authors:
+                    if author_str:
+                        author_list.append(
+                            Author.objects.get_or_create(name=author_str)[0]
+                        )
+
             for k, v in bdict.items():
                 setattr(book, k, v)
                 book.save()
 
                 book.save_image_from_url(cover)
                 book.genre.add(*genres)
+                book.authors.add(*author_list)
         return book
 
     def save_image_from_url(self, url: str, force_update: bool = False):