How to withdraw different querisets in Django Rest framework?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
12 views
Maybe a little bit wrong question formulated. In General, do not understand how to bring using DRF various collections of objects. Trying to understand by analogy with django views. I have to get a list of all locations, a list of the most popular and a list of editor's 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, })


And then have the template display for example 3 tables with the parameters I need.

Make API

**serializer.py**

class PlaeceSerializer(serializers.ModelSerializer): class Meta: model = Places fields = ( 'main_photo', 'name', )


**views.py**

class PlacesListAPIView(ListAPIView): queryset = Places.objects.all() serializer_class = PlaeceSerializer


So I have formed a collection of json containing all the objects. How to sample in views.py or as that work at the front with the received data? Share your experience, please. Preferably with explanation of process )
by | 12 views

1 Answer

0 like 0 dislike
www.django-rest-framework.org/api-guide/renderers

see for yourself how much data you have
if a little, all in a single json and renders via push the link above
if a lot,
\rwww.django-rest-framework.org/api-guide/filtering

and the front let pulls this url with parameters
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,405 users