Commit 2b822777 authored by Erlend Ydse's avatar Erlend Ydse
Browse files

Remove unused like-feature

parent aef5aa99
Pipeline #128395 passed with stage
in 1 minute and 10 seconds
# Generated by Django 3.1 on 2021-04-15 15:35
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('comments', '0001_initial'),
]
operations = [
migrations.DeleteModel(
name='Like',
),
]
...@@ -30,19 +30,3 @@ class Comment(models.Model): ...@@ -30,19 +30,3 @@ class Comment(models.Model):
class Meta: class Meta:
ordering = ["-timestamp"] ordering = ["-timestamp"]
class Like(models.Model):
"""Django model for a reaction to a comment.
Attributes:
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)
from rest_framework import serializers from rest_framework import serializers
from rest_framework.serializers import HyperlinkedRelatedField from rest_framework.serializers import HyperlinkedRelatedField
from comments.models import Comment, Like from comments.models import Comment
from workouts.models import Workout from workouts.models import Workout
...@@ -13,14 +13,3 @@ class CommentSerializer(serializers.HyperlinkedModelSerializer): ...@@ -13,14 +13,3 @@ class CommentSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Comment model = Comment
fields = ["url", "id", "owner", "workout", "content", "timestamp"] 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"]
from django.urls import path, include from django.urls import path, include
from comments.models import Comment, Like from comments.models import Comment
from comments.views import CommentList, CommentDetail, LikeList, LikeDetail from comments.views import CommentList, CommentDetail
from rest_framework.urlpatterns import format_suffix_patterns from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = [ urlpatterns = [
path("api/comments/", CommentList.as_view(), name="comment-list"), path("api/comments/", CommentList.as_view(), name="comment-list"),
path("api/comments/<int:pk>/", CommentDetail.as_view(), name="comment-detail"), path("api/comments/<int:pk>/", CommentDetail.as_view(), name="comment-detail"),
path("api/likes/", LikeList.as_view(), name="like-list"),
path("api/likes/<int:pk>/", LikeDetail.as_view(), name="like-detail"),
] ]
from django.shortcuts import render from django.shortcuts import render
from rest_framework import generics, mixins from rest_framework import generics, mixins
from comments.models import Comment, Like from comments.models import Comment
from rest_framework import permissions from rest_framework import permissions
from comments.permissions import IsCommentVisibleToUser from comments.permissions import IsCommentVisibleToUser
from workouts.permissions import IsOwner, IsReadOnly from workouts.permissions import IsOwner, IsReadOnly
from comments.serializers import CommentSerializer, LikeSerializer from comments.serializers import CommentSerializer
from django.db.models import Q from django.db.models import Q
from rest_framework.filters import OrderingFilter from rest_framework.filters import OrderingFilter
...@@ -77,43 +77,3 @@ class CommentDetail( ...@@ -77,43 +77,3 @@ class CommentDetail(
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
return self.destroy(request, *args, **kwargs) return self.destroy(request, *args, **kwargs)
# List of likes
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):
serializer.save(owner=self.request.user)
def get_queryset(self):
return Like.objects.filter(owner=self.request.user)
# Details of like
class LikeDetail(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
generics.GenericAPIView,
):
queryset = Like.objects.all()
serializer_class = LikeSerializer
permission_classes = [permissions.IsAuthenticated]
_Detail = []
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)
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