Answer the question
In order to leave comments, you need to log in
How to output different querisets in Django Rest framework?
Perhaps the question was formulated a little incorrectly. In general, I don’t understand how to display various collections of objects using DRF. I'm trying to understand by analogy with django views. I need to display a list of all places, a list of the most popular and a list of editors' choice.
def places_list(request):
places = Places.objects.all()
editor_places = Places.objects.filter(editor_choice = True )
popular_places = Places.objects.filter(most_popular = True )
return render (request, "places/places_list.html", {"places": places,
"editor_places": editor_places,
"popular_places": popular_places,
})
class PlaeceSerializer(serializers.ModelSerializer):
class Meta:
model = Places
fields = (
'main_photo',
'name',
)
class PlacesListAPIView(ListAPIView):
queryset = Places.objects.all()
serializer_class = PlaeceSerializer
Answer the question
In order to leave comments, you need to log in
www.django-rest-framework.org/api-guide/renderers
see for yourself how much data
you have, if a little, then all in one json and through renders display the link above
if there is a lot, then
www.django-rest-framework.org /api-guide/filtering
and let the front pull this url with parameters
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question