class ArticleList(generics.ListCreateAPIView):
queryset= Article.objects.all().filter(category=14).order_by('-created')[:10]
serializer_class= ArticleSerializer
url(r'^api/cat/(?P<category>[0-9]+)/$',views.ArticleList.as_view()),
class ArticleList(generics.ListCreateAPIView):
serializer_class= ArticleSerializer
def get_queryset(self):
category = self.request.GET.get('category', None)
if category:
return Article.objects.all().filter(category=category).order_by('-created')[:10]
else
return Article.objects.all().filter().order_by('-created')[:10]