Django Project parsing parameters in request
<p>I have request to my django project from ExtJS application:</p>

<pre><code>GET /products/?page=1&amp;start=0&amp;limit=25&amp;sort=%5B%7B%22property%22%3A%22id%22%2C%22direction%22%3A%22DESC%22%7D%5D 
</code></pre>

<p>At the request contains 4 parameters, one of which is a complex, which is called <strong>sort</strong>:</p>

<p><a href="http://i.stack.imgur.com/tVqIA.png" rel="nofollow"><img src="http://i.stack.imgur.com/tVqIA.png" alt="screen"></a></p>

<p>Question: how to extract the values of the parameters <strong>property</strong> and <strong>direction</strong> using Python? </p>

<p>I did so, but it does not work. I would be glad of any help.</p>

<pre class="lang-python prettyprint-override"><code>class ProductsList(generics.ListCreateAPIView):
    serializer_class = ProductsSerializer

    def get_queryset(self):

        queryset = Products.objects.all()
        sortParameter = self.request.query_params.get('sort', None)
        column_name=sortParameter['property']
        queryset = queryset.order_by(column_name)
        return queryset
</code></pre>

<p>If you know the best way to sort and filter the data on the server side for Django Rest projects, please share your ideas or references.</p>

<p>I solved the problem by using json package. Thanks for the advice <strong><em>furas</em></strong></p>

<pre><code>def get_queryset(self):

        queryset = Products.objects.all()
        sortParameter = self.request.query_params.get('sort', None)
        parsed_sort=json.loads(sortParameter)
        column_name=parsed_sort[0]['property']

        queryset = queryset.order_by(column_name)
        return queryset
</code></pre>

<p>But I think the code is not optimal? What is the best practice: build url on backend side  then send a request to the server and the server to do a minimum number of operations to retrieve the request parameters. Or parse request parameters on the server side.</p>

python django extjs django-rest-framework