Skip to content

filter the query set with attribute #2

Description

@rafiulgits

class UserProfileViewSet(viewsets.ModelViewSet):

from rest_framework.views import APIView
from rest_framework.responses import Response
from profile.models import ProfileSettings
from profile.serializers import ProfileSerializer

class ProfileView(APIView):
	def get(self, request):
		foodie_partner = request.GET.get('foodie_partner', None)
		location_range = request.GET.get('location_range', None)
		min_age = request.GET.get('min_age', None)
		max_age = request.GET.get('max_age', None)

		# Here I am using 1 level query
		# Use others 
		# REMEMBER: min_age and max_age is integer, so use greater/less/equal
		# 	Ref: https://stackoverflow.com/questions/10040143/#10040165
		query = ProfileSettings.objects.filter(foodie_partner__iexact=foodie_partner).only()
		serializer = ProfileSerializer(query, many=True)
		return Response(serializer.data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions