Skip to content

Commit

Permalink
first urls , testing Serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
shing100 committed Jul 29, 2018
1 parent f90db23 commit 74673c3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ king_cats = king.cat_set.all()
- https://hackernoon.com/restful-api-designing-guidelines-the-best-practices-60e1d954e7c9
- https://www.django-rest-framework.org

> Django Rest Framework Serializers
- http://www.django-rest-framework.org/api-guide/serializers/

> URL dispatcher
- https://docs.djangoproject.com/en/1.11/topics/http/urls/
- https://docs.djangoproject.com/en/2.0/ref/urls/#path
4 changes: 4 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"users/",
include("limstagram.users.urls", namespace="users"),
),
path(
"images/",
include("limstagram.images.urls", namespace="images"),
),
path("accounts/", include("allauth.urls")),
# Your stuff: custom urls includes go here
] + static(
Expand Down
6 changes: 3 additions & 3 deletions limstagram/images/serializers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from rest_framework import serializers
from . import models

class ImageSerializer(serializers.Serializer):
class ImageSerializer(serializers.ModelSerializer):

class Meta:
model = models.Image
fields = '__all__'

class CommentSerializer(serializers.Serializer):
class CommentSerializer(serializers.ModelSerializer):

class Meta:
model = models.Comment
fidels = '__all__'

class LikeSerializer(serializers.Serializer):
class LikeSerializer(serializers.ModelSerializer):

class Meta:
models = models.Like
Expand Down
10 changes: 3 additions & 7 deletions limstagram/images/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from django.conf.urls import url
from django.urls import path
from . import views

app_name = "images"
urlpatterns = [
url(
regex=r'^all/$',
view=views.ListAllImages.as_view(),
name='all_images'
)
]
path("all/", view=views.ListAllImages.as_view(), name="all_images"),
]
14 changes: 12 additions & 2 deletions limstagram/images/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from . import models, serializers

# Create your views here.
class ListAllImages(APIView):

def get(self, request, format=None):
# 모든 이미지를 불러옴
all_images = models.Image.objects.all()
# 모든 이미지를 시리얼라이즈 (변환)
serializer = serializers.ImageSerializer(all_images, many=True)

return Response(data=serializer.data)

0 comments on commit 74673c3

Please sign in to comment.