Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django RestFramework 사용하기 #35

Open
gincheong opened this issue Apr 4, 2021 · 3 comments
Open

Django RestFramework 사용하기 #35

gincheong opened this issue Apr 4, 2021 · 3 comments

Comments

@gincheong
Copy link
Owner

No description provided.

@gincheong
Copy link
Owner Author

gincheong commented Apr 4, 2021

pip install djangorestframework django-filter markdown
# [PROJECT_NAME]/settings.py

INSTALLED_APP = [
  ... ,
  'rest_framework' # 추가
]

@gincheong
Copy link
Owner Author

# [APP_NAME]/seriallizers.py (새로 생성)
# 여기서 Task는 임의로 만든 모델임

from rest_framework import serializers

from .models import Task

class TaskSerializers(serializers.ModelSerializer):
    class Meta:
        model = Task
        fields = '__all__'

@gincheong
Copy link
Owner Author

# [APP_NAME]/views.py

from rest_framework import viewsets
from django_filters.rest_framework import DjangoFilterBackend

from .models import Product
from .serializers import ProductSerializers

class ProductViewSet(viewsets.ModelViewSet):
    queryset = Product.objects.all()
    serializer_class = ProductSerializers

    filter_backends = (DjangoFilterBackend, )
    filter_fields = '__all__'
    
    # 여기서 list, retrieve 함수 등을 정의하는 것으로 override 가능함

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant