Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
How to sort GET query according to the specified rules

I'm using url_replace to add GET query like below.

@register.simple_tag
def url_replace(request, field, value):
    get_params = request.GET.copy()
    get_params[field] = value
    return get_params.urlencode()

<p>[ Category ]</p>
<ul>
    {% for cat in cats %}
    <li><a href="?{% url_replace request 'category' cat.slug %}">{{ cat.name }}</a></li>
    {% endfor %}
</ul>
<p>[ Job Type ]</p>
<ul>
    {% for type_value, type_name in types %}
    <li><a href="?{% url_replace request 'type' type_value %}">{{ type_name }}</a></li>
    {% endfor %}
</ul>

It arranges GET query every time clicks specified link. For example:

1)
current URL: /jobs/
click <a href="?{% url_replace request 'category' cat.slug %}">{{ cat.name }}</a>
URL changes: /jobs/?category=cat.slug
then click <a href="?{% url_replace request 'type' type_value %}">{{ type_name }}</a>
URL changes: /jobs/?category=cat.slug&type=type_value

2)
current URL: /jobs/
click <a href="?{% url_replace request 'type' type_value %}">{{ type_name }}</a>
URL changes: /jobs/?type=type_value
then click <a href="?{% url_replace request 'category' cat.slug %}">{{ cat.name }}</a>
URL changes: /jobs/?type=type_value&category=cat.slug

But I want to sort these GET queries always category first and next is type.

always: /jobs/?category=cat.slug&type=type_value
not: /jobs/?type=type_value&category=cat.slug

How can I do this?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!