Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
75 views
in Technique[技术] by (71.8m points)

python - Drop Down List Selection

When I select a drop down list value, it inserts it into my helper.py query. However, the drop down significantly reduced to just that one selection. I have to hit the back button to see all of my drop down values since it does not repopulate on the new page. Is there a way i can keep selecting different values from drop down, even in the new query result page?

Actual Result

Drop down List:

Chris
Evan
Patty
    

Then if I choose Chris on the drop menu then Evan and Patty disappear when it narrows the query results and inputs Chris in my query.

drop down list:
Chris

code helper.py

def EmployeeBalancing(get_dropdown_value, procdate):
    cursor = connection.cursor()
    print(cursor.execute(f'''select distinct to_char(processingdate,'YYYY-MM-DD'), opstattypeskey, loginname, firstname, lastname, active_time, idle_time, items, keys, rejects,bypass,b_function,
    from ppc_data.emp_performance where to_char(processingdate,'YYYY-MM-DD') = '{procdate}' and loginname='{get_dropdown_value}' 
    order by to_char(processingdate,'YYYY-MM-DD'), opstattypeskey, loginname, firstname, lastname, active_time, idle_time, items, keys, rejects,bypass,b_function desc '''))
    query = cursor.fetchall()
    return query

def EmployeeBalancing_Null():
    cd = datetime.now().strftime('%Y-%m-%d')
    print(cd)
    cursor = connection.cursor()
    cursor.execute(f'''select distinct to_char(processingdate,'YYYY-MM-DD'), opstattypeskey, loginname, firstname, lastname, active_time, idle_time, items, keys, rejects,bypass,b_function,
                       from ppc_data.emp_performance order by to_char(processingdate,'YYYY-MM-DD'), opstattypeskey, loginname, firstname, lastname, active_time, idle_time, items, keys, rejects,bypass,b_function desc''')
    query = cursor.fetchall()
    return query

views.py

def stats(request):

if request.method == 'POST':
    loginname = request.POST['loginname']
    procdate = request.POST['procdate']
    print(loginname)
    return render(request, r'C:UsersTESTprojectsppcstatsemplatesemplate.html',{'EmployeeBalancing': EmployeeBalancing(loginname, procdate)})
return render(request, r'C:UsersTESTprojectsppcstatsemplatesemplate.html',{'EmployeeBalancing': EmployeeBalancing_Null()})

template.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form action="{%url 'stats'%}" method="post">{% csrf_token %}
        <select name="loginname" onchange="javascript:this.form.submit()">
            {% for obj in EmployeeBalancing %}
                <option value="{{obj.2}}">{{obj.2}}</option>
            {% endfor %}
        </select>
    <select name="procdate" onchange="javascript:this.form.submit()" >
            {% for obj in EmployeeBalancing %}
                <option value="{{obj.0}}">{{obj.0}}</option>
            {% endfor %}
        </select>
    </form>
question from:https://stackoverflow.com/questions/65902476/drop-down-list-selection

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...