0

I was assigned with a task which required me to understand the following Python code which uses jQuery and datatable:

req = request.GET
sort_col = req['columns[%s][data]' % req['order[0][column]']]
glob_search_val = req['search[value]']
if req['order[0][dir]'] != 'asc':

I'm new to jQuery and datatables. The usage is quite different from how normal Python lists/dictionaries are accessed. For example, order[0][column] apparently is a variable but it's quoted which means a literal in Python. the column in the bracket appears to be a variable, it's again inside quotes and not initialized. In datables documentation order is an 2D array access by index like order[0][0]. I have similar question for data in columns[%s][data] and what does columns[%s][data] return?

Where can I find more information on how columns, order, search (and other) parameters work in Django?

1 Answer 1

1

Those parameter names you reference (sort, columns, search) are just keys in a request.GET QueryDict. There's nothing intrinsic to Django about those parameter names in a GET request (i.e. nothing magical happens in Django with those parameter key names).

The %s and %s are part of old-style python string formatting, so the %s will be replaced by whatever is in req['order[0][column]] which will then store the sort column field name in sort_col.

As far as actual filtering/searching/ordering etc in Django, that's through the Django QuerySet API. Presumably you will be sorting/ordering/searching a list of objects stored in a Database and defined in whatever Model was displayed in your Datatable e.g. FooModel.objects.filter(some_field=search_val).order_by(sort_col)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.