인코스런 2기

Day4 - 장고 온보딩 프로젝트 4

B1001101 2022. 6. 10. 23:46

학습한 내용

FilterSets NumberFilter

from django_filters import rest_framework as filters

class MovieFilter(filters.FilterSet):
    avg_rating_filter = filters.NumberFilter(field_name='avg_rating', lookup_expr='gte', label="avg_rating (greater than or equal)")

 

Views & Serializers - Foreign Key

from django.db.models import Prefetch

class MovieDetailUpdateDeleteView(generics.RetrieveUpdateDestroyAPIView):
    queryset = Movie.objects.all().prefetch_related(
        Prefetch("review_set", queryset = Review.objects.order_by('-created'))
    )

 

Paginations - 모든 뷰에서 사용

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS' : 'api.v1.common.paginations.DefaultPagination',
}