Skip to content

Commit

Permalink
image tag serializer 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
shing100 committed Aug 19, 2018
1 parent 3a16714 commit 19d237f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ urlpatterns = [
- https://github.com/alex/django-taggit
- https://django-taggit.readthedocs.io/en/latest/
- https://github.com/glemmaPaul/django-taggit-serializer

> field-lookups
Expand Down
3 changes: 2 additions & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
'allauth.account',
'allauth.socialaccount',
'rest_framework', # REST Framework
'taggit' # Tags for the photos
'taggit', # Tags for the photos
'taggit_serializer'
]
LOCAL_APPS = [
'limstagram.users.apps.UsersAppConfig',
Expand Down
5 changes: 3 additions & 2 deletions limstagram/images/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from rest_framework import serializers
from . import models
from taggit_serializer.serializers import (TagListSerializerField,TaggitSerializer)
from limstagram.users import models as user_models


Expand Down Expand Up @@ -52,12 +53,12 @@ class Meta:
model = models.Like
fields = '__all__'


class ImageSerializer(serializers.ModelSerializer):

# 필드의 전체 내용을 불러옴
comments = CommentSerializer(many=True)
creator = FeedUserSerializer()
tags = TagListSerializerField()

class Meta:
model = models.Image
Expand All @@ -68,7 +69,7 @@ class Meta:
'caption',
'comments',
'like_count',
'creator'
'creator',
'tags'
)

6 changes: 4 additions & 2 deletions limstagram/images/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.response import Response
from rest_framework import status
from . import models, serializers
from limstagram.notifications import views as notification_views

class Feed(APIView):

Expand Down Expand Up @@ -85,8 +86,6 @@ class CommentOnImage(APIView):

def post(self, request, image_id, format=None):

## notificarion

user = request.user
serializer = serializers.CommentSerializer(data=request.data)

Expand All @@ -97,6 +96,9 @@ def post(self, request, image_id, format=None):

if serializer.is_valid():
serializer.save(creator=user, image=found_image)
## notificarion
notification_views.create_notification(user, found_image.creator, 'comment', serializer.data['message'])

return Response(data=serializer.data, status=status.HTTP_201_CREATED)

else:
Expand Down
13 changes: 13 additions & 0 deletions limstagram/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@ def get(self, request, format=None):
serializer = serializers.NotificationSerializer(notifications, many=True)

return Response(data=serializer.data, status=status.HTTP_200_OK)


def create_notification(creator, to, notification_type, image=None, comment=None):

notification = models.Notification.objects.create(
creator = creator,
to = to,
notification_type=notification_type,
image = image,
comment = comment
)

notification.save()
3 changes: 3 additions & 0 deletions limstagram/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rest_framework.response import Response
from rest_framework import status
from . import models, serializers
from limstagram.notifications import views as notification_views

class ExploreUsers(APIView):

Expand Down Expand Up @@ -29,6 +30,8 @@ def post(self, request, user_id, format=None):
user.following.add(user_to_follow)
user.save()

notification_views.create_notification(user, user_to_follow, 'follow')

return Response(status=status.HTTP_200_OK)

class UnFollowUser(APIView):
Expand Down

0 comments on commit 19d237f

Please sign in to comment.