我有以下代码:
class OrderListViewSet(viewsets.ModelViewSet,
ReadOnlyCacheResponseAndETAGMixin):
permission_classes = (NoUpdatePermission,)
model_class = Order
lookup_field = 'unique_reference'
serializer_class = OrderSerializer
pagination_class = OrderPagination
@method_decorator(cache_page(settings.ORDER_CACHE_LIFETIME))
def dispatch(self, *args, **kwargs):
return super(OrderListViewSet, self).dispatch(*args, **kwargs)
def get_serializer_class(self):
if self.request.method == 'POST':
return CreateOrderSerializer
return super(OrderListViewSet, self).get_serializer_class()
def get_queryset(self, filters=None, **kwargs):
self.queryset = Order.objects.all()
return super(OrderListViewSet, self).get_queryset()
def perform_create(self, serializer):
if not self.request.user.is_authenticated:
_create_anonymous_user(self.request)
serializer.save(user=self.request.user)
return super(OrderListViewSet, self).perform_create(serializer)
我想迁移到:
class OrderListViewSet(viewsets.ModelViewSet,
ReadOnlyCacheResponseAndETAGMixin):
permission_classes = (NoUpdatePermission,)
model_class = Order
lookup_field = 'unique_reference'
serializer_class = OrderSerializer
pagination_class = OrderPagination
@method_decorator(cache_page(settings.ORDER_CACHE_LIFETIME))
def dispatch(self, *args, **kwargs):
return super(OrderListViewSet, self).dispatch(*args, **kwargs)
def get_serializer_class(self):
if self.request.method == 'POST':
return CreateOrderSerializer
return super(OrderListViewSet, self).get_serializer_class()
def get_queryset(self, filters=None, **kwargs):
self.queryset = Order.objects.all()
return super(OrderListViewSet, self).get_queryset()
def perform_create(self, serializer):
if not self.request.user.is_authenticated:
_create_anonymous_user(self.request)
serializer.save(user=self.request.user)
return super(OrderListViewSet, self).perform_create(serializer)
我的目标是将ListView
缓存60秒,而不是DetailView
(始终从那里返回最新数据,因为它用于长时间拉动)。
我得到的错误是:
TypeError: never_cache() missing 1 required positional argument: 'view_func'
一起移除never_cache
装饰器是否合理?