Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4095798
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:56:48+00:00 2026-05-20T19:56:48+00:00

I have created an Employee management system using Django. I have done a filtering

  • 0

I have created an Employee management system using Django. I have done a filtering method in it and is based on a choice selected from a drop down menu and a text input. the filtering is working fine. On the first page it gives the entire employee list which can be shown in both ascending and descending order. On the same page is given the filtering method. The filtered data is shown in another page. Now i want to give a button on the filtered data page, clicking on that button shows the data in ascending/descending. I have written a separate function for ascending and descending in views for the full employee listing. How can it be used for this functionality. I will paste my code here. Please help me to find a solution as i am new to django programming.
I have given 2 separate images for ascending and descending.I want it this way: Clicking on 1 image lists in ascending order; and clicking on other image lists it in descending order.

Filter()

def filter(request):
    val3='' 
    if request.GET.has_key('choices'):
        val2=request.GET.get('choices')
    if request.GET.has_key('textField'):
        val3=request.GET.get('textField')
    if request.POST:
        val2=request.POST.get('choices')    
        val3=request.POST.get('textField')
    if val2=='Designation':                
        newData = EmployeeDetails.objects.filter(designation=val3) 
        flag=True 
    elif val2=='Name':
        newData = EmployeeDetails.objects.filter(userName__icontains=val3)
        flag=True 
    elif val2=='EmployeeID':
        newData = EmployeeDetails.objects.filter(employeeID=val3)  
        flag=True       
    elif val2=='Project':
        newData = EmployeeDetails.objects.filter(project=val3)   
        flag=True   
    elif val2=='DateOfJoin':
        newData = EmployeeDetails.objects.filter(dateOfJoin=val3) 
        flag=True       
    else:
        return HttpResponseRedirect('/employeeList/')    
    #tableList = EmployeeDetails.objects.all()
    paginator = Paginator(newData, 10)    
    try:
         page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        contacts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        contacts = paginator.page(0)               
    return render_to_response('filter.html',{'newData':newData,'emp_list': contacts,'val2':val2,'val3':val3,'flag':flag})        

filter.html

<div>
Employees List&nbsp;&nbsp;
<a STYLE="text-decoration:none" align=center href="http://10.1.0.90:8080/sortAscend/ "> <img  src="/static/sort_asc.gif " border="1" height="12" /> </a>
<h4 align="left">
{%for data in newData%}
<a STYLE="text-decoration:none" href ="http://10.1.0.90:8080/singleEmployee/{{data.id}}?choices={{val2}}&textField={{val3}}&flag=1 ">
{{ data.userName}}<br>
{%endfor%} 
</h4>
</div>

ascending and descending functions

def sortAscend(request):
    tableList = EmployeeDetails.objects.all().order_by('userName')
    paginator = Paginator(tableList, 12)    
    try:
         page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        contacts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        contacts = paginator.page(0)
    return render_to_response('sortAscend.html', {'emp_list': contacts})

#Method for listing the employees in descending order
def sortDescend(request):
    tableList = EmployeeDetails.objects.all().order_by('-userName')
    paginator = Paginator(tableList, 12)    
    try:
         page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        contacts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        contacts = paginator.page(0)
    return render_to_response('sortDescend.html', {'emp_list': contacts})

sortAscending.html

{%for emp in emp_list.object_list%}
    <tr> <td><a STYLE="text-decoration:none" href ="http://10.1.0.90:8080/singleEmployee/{{emp.id}} "> {{ emp.userName }} </a></td> </tr><td>
{%endfor%}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:56:49+00:00Added an answer on May 20, 2026 at 7:56 pm

    Another alternative to handling sorting in the view level is to do it on the templates. For this reason, you might want to checkout jquery tablesorter (since you are using a table in the display as well). It handles sorting in ascending/descending order.

    So if you have the results after filtering that is ready to be displayed to a page, say filtered_results.html, you can do it like this.

    <!-- filtered_results.html -->
    <head>
       ...
       <script type="text/javascript" src="/path/to/jquery-latest.js"></script> 
       <script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script> 
       <script type="text/javascript">
           $(document).ready(function() {
               $("#myTable").tablesorter();
           });
       </script>
    </head>
    <body>
        <table id="myTable">
            <thead><tr><th>Some-Label</th></tr></thead>
            <tbody>
            {% for emp in emp_list.object_list %}
                <tr><td><a href="http://10.1.0.90:8080/singleEmployee/{{emp.id}}">{{emp.userName}}</a></td></tr>
            {% endfor %}
            </tbody>
        </table>
    </body>
    

    Clicking on the cell of ‘Some-Label’ will toggle the sorting in ascending/descending order.

    Furthermore, it has a plugin for handling pagination. Check out this link for the demo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a django application. Using this app users can be created or
I have created a mac application using the WebView. But issue is that webView
I have created a Layout using ExtJs. It consists of a left menu and
If I have created the following Employee object (simplified)... public class Employee { public
I have inherited the maintenance of a database from a former employee in another
(just learning MVC) I have created a model class: public class Employee { public
I have created a method in my java assignment to write into a file
I'm working on Employee Management System. Each employee belong to one department, when employee
We have a time management system where our employees or contractors (resources) enter the
i have created that table on my sql server : create table Empolyee( ESSN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.