Commit 1c6d76d4 authored by andrerim's avatar andrerim
Browse files

Remove unused 'like' feature

parent fe1b47f2
Pipeline #129748 passed with stage
in 1 minute and 26 seconds
# Generated by Django 3.1 on 2021-04-19 19:14
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('comments', '0001_initial'),
operations = [
......@@ -25,19 +25,3 @@ class Comment(models.Model):
class Meta:
ordering = ["-timestamp"]
class Like(models.Model):
"""Django model for a reaction to a comment.
owner: Who liked the comment
comment: The comment that was liked
timestamp: When the like occurred.
owner = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="likes"
comment = models.ForeignKey(Comment, on_delete=models.CASCADE, related_name="likes")
timestamp = models.DateTimeField(auto_now_add=True)
......@@ -2,7 +2,6 @@ from rest_framework import serializers
from rest_framework.serializers import HyperlinkedRelatedField
from comments.models import Comment
from comments.models import Like
from workouts.models import Workout
......@@ -15,14 +14,3 @@ class CommentSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Comment
fields = ["url", "id", "owner", "workout", "content", "timestamp"]
class LikeSerializer(serializers.HyperlinkedModelSerializer):
owner = serializers.ReadOnlyField(source="owner.username")
comment = HyperlinkedRelatedField(
queryset=Comment.objects.all(), view_name="comment-detail"
class Meta:
model = Like
fields = ["url", "id", "owner", "comment", "timestamp"]
......@@ -2,12 +2,8 @@ from django.urls import path
from comments.views import CommentDetail
from comments.views import CommentList
from comments.views import LikeDetail
from comments.views import LikeList
urlpatterns = [
path("comments/", CommentList.as_view(), name="comment-list"),
path("comments/<int:pk>/", CommentDetail.as_view(), name="comment-detail"),
path("likes/", LikeList.as_view(), name="like-list"),
path("likes/<int:pk>/", LikeDetail.as_view(), name="like-detail"),
......@@ -5,10 +5,8 @@ from rest_framework import permissions
from rest_framework.filters import OrderingFilter
from comments.models import Comment
from comments.models import Like
from comments.permissions import IsCommentVisibleToUser
from comments.serializers import CommentSerializer
from comments.serializers import LikeSerializer
from workouts.permissions import IsOwner
from workouts.permissions import IsReadOnly
......@@ -80,40 +78,3 @@ class CommentDetail(
def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
class LikeList(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView):
serializer_class = LikeSerializer
permission_classes = [permissions.IsAuthenticated]
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
return self.create(request, *args, **kwargs)
def perform_create(self, serializer):
def get_queryset(self):
return Like.objects.filter(owner=self.request.user)
class LikeDetail(
queryset = Like.objects.all()
serializer_class = LikeSerializer
permission_classes = [permissions.IsAuthenticated]
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
def put(self, request, *args, **kwargs):
return self.update(request, *args, **kwargs)
def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs)
......@@ -17,6 +17,5 @@ def api_root(request, format=None):
"workout-file-list", request=request, format=format
"comments": reverse("comment-list", request=request, format=format),
"likes": reverse("like-list", request=request, format=format),
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment