Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter the query set with attribute #2

Open
rafiulgits opened this issue Oct 22, 2019 · 0 comments
Open

filter the query set with attribute #2

rafiulgits opened this issue Oct 22, 2019 · 0 comments

Comments

@rafiulgits
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant