diff --git a/books/models.py b/books/models.py index 06ed574f..746ac1b6 100644 --- a/books/models.py +++ b/books/models.py @@ -122,6 +122,11 @@ class Book(Entity): def mark_class(self): return BookMark + @property + def tag_class(self): + return BookTag + + class BookMark(Mark): book = models.ForeignKey( Book, on_delete=models.CASCADE, related_name='book_marks', null=True) diff --git a/common/models.py b/common/models.py index 2cbec5b8..07d2261e 100644 --- a/common/models.py +++ b/common/models.py @@ -192,6 +192,10 @@ class Entity(models.Model): def mark_class(self): raise NotImplementedError("Subclass should implement this.") + @property + def tag_class(self): + raise NotImplementedError("Subclass should implement this.") + class UserOwnedEntity(models.Model): is_private = models.BooleanField(default=False, null=True) # first set allow null, then migration, finally (in a few days) remove for good @@ -281,6 +285,11 @@ class Mark(UserOwnedEntity): def translated_status(self): raise NotImplementedError("Subclass should implement this.") + @property + def tags(self): + tags = self.item.tag_class.objects.filter(mark_id=self.id) + return tags + class Meta: abstract = True constraints = [ diff --git a/games/models.py b/games/models.py index a47e8104..c51e2981 100644 --- a/games/models.py +++ b/games/models.py @@ -108,6 +108,10 @@ class Game(Entity): def mark_class(self): return GameMark + @property + def tag_class(self): + return GameTag + class GameMark(Mark): game = models.ForeignKey( diff --git a/movies/models.py b/movies/models.py index 63a7523c..70b4b7c6 100644 --- a/movies/models.py +++ b/movies/models.py @@ -235,6 +235,10 @@ class Movie(Entity): def mark_class(self): return MovieMark + @property + def tag_class(self): + return MovieTag + class MovieMark(Mark): movie = models.ForeignKey(Movie, on_delete=models.CASCADE, related_name='movie_marks', null=True) diff --git a/music/models.py b/music/models.py index 11a931ca..9afa0b53 100644 --- a/music/models.py +++ b/music/models.py @@ -87,6 +87,10 @@ class Album(Entity): def mark_class(self): return AlbumMark + @property + def tag_class(self): + return AlbumTag + class Song(Entity): ''' @@ -142,6 +146,10 @@ class Song(Entity): def mark_class(self): return SongMark + @property + def tag_class(self): + return SongTag + class SongMark(Mark): song = models.ForeignKey( diff --git a/users/export.py b/users/export.py index 65faab6d..372285d5 100644 --- a/users/export.py +++ b/users/export.py @@ -48,7 +48,7 @@ def export_marks_task(user): movie = mark.movie title = movie.title summary = str(movie.year) + ' / ' + ','.join(movie.area) + ' / ' + ','.join(map(lambda x: str(MovieGenreTranslator[x]), movie.genre)) + ' / ' + ','.join(movie.director) + ' / ' + ','.join(movie.actor) - tags = ','.join(list(set(map(lambda t: t['content'], movie.get_tags_manager().values())))) + tags = ','.join(list(map(lambda m: m.content, mark.tags))) world_rating = (movie.rating / 2) if movie.rating else None timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S') my_rating = (mark.rating / 2) if mark.rating else None @@ -66,7 +66,7 @@ def export_marks_task(user): album = mark.album title = album.title summary = ','.join(album.artist) + ' / ' + (album.release_date.strftime('%Y') if album.release_date else '') - tags = ','.join(list(set(map(lambda t: t['content'], album.get_tags_manager().values())))) + tags = ','.join(list(map(lambda m: m.content, mark.tags))) world_rating = (album.rating / 2) if album.rating else None timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S') my_rating = (mark.rating / 2) if mark.rating else None @@ -84,7 +84,7 @@ def export_marks_task(user): book = mark.book title = book.title summary = ','.join(book.author) + ' / ' + str(book.pub_year) + ' / ' + book.pub_house - tags = ','.join(list(set(map(lambda t: t['content'], book.get_tags_manager().values())))) + tags = ','.join(list(map(lambda m: m.content, mark.tags))) world_rating = (book.rating / 2) if book.rating else None timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S') my_rating = (mark.rating / 2) if mark.rating else None @@ -102,7 +102,7 @@ def export_marks_task(user): game = mark.game title = game.title summary = ','.join(game.genre) + ' / ' + ','.join(game.platform) + ' / ' + (game.release_date.strftime('%Y-%m-%d') if game.release_date else '') - tags = ','.join(list(set(map(lambda t: t['content'], game.get_tags_manager().values())))) + tags = ','.join(list(map(lambda m: m.content, mark.tags))) world_rating = (game.rating / 2) if game.rating else None timestamp = mark.edited_time.strftime('%Y-%m-%d %H:%M:%S') my_rating = (mark.rating / 2) if mark.rating else None