I’m making a request via GET with the following query:
site.org/mymodel?ordering=-created&state=awaiting_review
and I have updated to send with multiple states:
But I have not found a doc in django that specifies how to treat it. So I’m not sure what to do right now. Maybe there is a vanilla option of how to do it.
The following codes are a mock of the current ones. What kind of function of part of django/python should I use to receive a filtered query with multiple values ?
the current one complains throwing this as response too.
{
"state": [
"Select a valid choice. awaiting_review,reviewed,phone_screened,interview_scheduled,interview_completed,offer_made,hired,rejected is not one of the available choices."
]
}
Should I change the URL too ?
Model.py: `
class MyModel():
STATE_OPTIONS = (
("awaiting_review", "awaiting_review"),
("reviewed", "reviewed"),
("phone_screened", "phone_screened"),
("interview_scheduled", "interview_scheduled"),
("interview_completed", "interview_completed"),
("offer_made", "offer_made"),
("hired", "hired"),
("rejected", "rejected"),
)
state = models.CharField(
max_length=19, choices=STATE_OPTIONS, default="awaiting_review", null=False
)
Serializer.py:
class ASerializer(serializers.ModelSerializer):
class Meta:
model = MyModel
fields = ( state )
`
view.py: `
class MyModelView(generics.ListAPIView, ProtectedResourceView):
serializer_class = ASerializer
filter_fields = ("state")
ordering_fields = ("state")
def get_queryset(self):
return MyModel.objects.filter(user=self.request.user).filter(
something_thats_not_state = self.request.query_params.get("something_thats_not_state")
)
`