diff --git a/portfolio/migrations/0002_auto_20200724_1012.py b/portfolio/migrations/0002_auto_20200724_1012.py new file mode 100644 index 0000000..96d376d --- /dev/null +++ b/portfolio/migrations/0002_auto_20200724_1012.py @@ -0,0 +1,35 @@ +# Generated by Django 3.0.8 on 2020-07-24 10:12 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('portfolio', '0001_initial'), + ] + + operations = [ + migrations.RenameModel( + old_name='CommentRating', + new_name='GuestCommentRating', + ), + migrations.AlterField( + model_name='guestcommentrating', + name='comment', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='portfolio.GuestComment'), + ), + migrations.CreateModel( + name='UserCommentRating', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('value', models.PositiveSmallIntegerField(choices=[(1, 'POSITIVE'), (0, 'NEGATIVE')], verbose_name='Type of rating (1 - POSITIVE, 0 - NEGATIVE)')), + ('comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='portfolio.UserComment')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='portfolio.Account')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/portfolio/migrations/__pycache__/0002_auto_20200724_1012.cpython-36.pyc b/portfolio/migrations/__pycache__/0002_auto_20200724_1012.cpython-36.pyc new file mode 100644 index 0000000..e7acac0 Binary files /dev/null and b/portfolio/migrations/__pycache__/0002_auto_20200724_1012.cpython-36.pyc differ diff --git a/portfolio/rating/__pycache__/models.cpython-36.pyc b/portfolio/rating/__pycache__/models.cpython-36.pyc index eccc71d..78f9c7d 100644 Binary files a/portfolio/rating/__pycache__/models.cpython-36.pyc and b/portfolio/rating/__pycache__/models.cpython-36.pyc differ diff --git a/portfolio/rating/__pycache__/serializers.cpython-36.pyc b/portfolio/rating/__pycache__/serializers.cpython-36.pyc index e6c6028..d38effe 100644 Binary files a/portfolio/rating/__pycache__/serializers.cpython-36.pyc and b/portfolio/rating/__pycache__/serializers.cpython-36.pyc differ diff --git a/portfolio/rating/__pycache__/views.cpython-36.pyc b/portfolio/rating/__pycache__/views.cpython-36.pyc index 3f5367e..1f41ff8 100644 Binary files a/portfolio/rating/__pycache__/views.cpython-36.pyc and b/portfolio/rating/__pycache__/views.cpython-36.pyc differ diff --git a/portfolio/rating/models.py b/portfolio/rating/models.py index 22ba31a..5d132c6 100755 --- a/portfolio/rating/models.py +++ b/portfolio/rating/models.py @@ -22,7 +22,7 @@ class AbstractRating(OneToManyModel): abstract = True -class CommentRating(AbstractRating): +class UserCommentRating(AbstractRating): comment = models.ForeignKey(UserComment, on_delete=models.CASCADE) def toDict(self): @@ -33,6 +33,17 @@ class CommentRating(AbstractRating): "comment_id": self.comment_id } +class GuestCommentRating(AbstractRating): + comment = models.ForeignKey(GuestComment, on_delete=models.CASCADE) + + def toDict(self): + return { + "id": self.id, + "user_id": self.user_id, + "value": self.value, + "comment_id": self.comment_id + } + class AlbumRating(AbstractRating): album = models.ForeignKey(Album, on_delete=models.CASCADE) diff --git a/portfolio/rating/serializers.py b/portfolio/rating/serializers.py index e832fb3..cc0c328 100644 --- a/portfolio/rating/serializers.py +++ b/portfolio/rating/serializers.py @@ -26,26 +26,26 @@ class TrackRatingSerializer(serializers.ModelSerializer): fields = ['id', 'user_id', 'value'] -class CommentRatingSerializer(serializers.ModelSerializer): +class UserCommentRatingSerializer(serializers.ModelSerializer): id = serializers.IntegerField(read_only = True) user_id = serializers.IntegerField() @staticmethod def get_default(comment_id): - queryset = CommentRating.objects.filter(comment_id=comment_id) + queryset = UserCommentRating.objects.filter(comment_id=comment_id) return [ x.toDict() for x in queryset ] @staticmethod def create(validated_data, comment_id): validated_data["comment_id"] = comment_id - return CommentRating.create(CommentRating, validated_data) + return UserCommentRating.create(UserCommentRating, validated_data) @staticmethod def delete(comment_id, user_id): - return CommentRating.objects.get(comment_id=comment_id, user_id=user_id).delete() + return UserCommentRating.objects.get(comment_id=comment_id, user_id=user_id).delete() class Meta: - model = CommentRating + model = UserCommentRating fields = ['id', 'user_id', 'value'] diff --git a/portfolio/rating/views.py b/portfolio/rating/views.py index 587d391..5cca452 100755 --- a/portfolio/rating/views.py +++ b/portfolio/rating/views.py @@ -7,8 +7,8 @@ from drf_yasg.utils import swagger_auto_schema from django.shortcuts import get_object_or_404 -from .models import TrackRating, AlbumRating, CommentRating -from .serializers import TrackRatingSerializer, AlbumRatingSerializer, CommentRatingSerializer +from .models import TrackRating, AlbumRating, UserCommentRating +from .serializers import TrackRatingSerializer, AlbumRatingSerializer, UserCommentRatingSerializer class TrackRatingViewSet( mixins.ListModelMixin, @@ -72,8 +72,8 @@ class CommentRatingViewSet( mixins.DestroyModelMixin, viewsets.GenericViewSet ): - queryset = CommentRating.objects.all() - serializer_class = CommentRatingSerializer + queryset = UserCommentRating.objects.all() + serializer_class = UserCommentRatingSerializer lookup_url_kwarg = 'user_id' def list(self, request, *args, **kwargs):