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 9310761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:11:45+00:00 2026-06-19T01:11:45+00:00

I have the following form that is manually rendered in a Django template. By

  • 0

I have the following form that is manually rendered in a Django template. By “manually rendered” I mean that there is no corresponding Form or ModelForm object in the code (the reasons/details for not using a Form object are a bit complex, and can be safely left out of this quesion). I have a mental block now and I can’t seem to work out how to get this data in a usable form within the Django view. Specifically, how do I get the respective attendance_value and attendance_remarks for each workers_pks when the form is POSTed?

<form>
<table>
    <thead>
        <tr>
            <th>Sl</th>
            <th>Worker</th>
            <th>Worker's Gender</th>
            <th>Work</th>
            <th>Unit cost of work</th>
            <th>Job</th>
            <th>Attendance</th> {# 1 or less if unit is day, 8 or less if unit is hours #}
            <th>Remarks</th> {# if any #}
        </tr>
    </thead>
    <tbody>
    {% for result in results %}
        <tr>
            <th>{{ forloop.counter }}</th>
            <td>{{ result.worker.name }} <input type="hidden" name="workers_pks" value="{{ result.worker.pk }}" id="id_workers_pks_{{ forloop.counter }}"></td>
            <td>{{ result.worker.get_gender_display }}</td>
            <td>{{ result.work.name }}</td>
            <td>{{ result.work.unit_cost }} per {{ result.work.work_unit }}</td>
            <td>{{ result.job_handover.job.name }}</td>
            <td>
                <input type='text' name='attendance_value' id='id_attendance_value_{{ forloop.counter }}' />
            </td>
            <td>
                <input type='text' name='attendance_remarks' id='id_attendance_remarks_{{ forloop.counter }}' />
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
</form>

Just to clarify, I know I can get the values by doing something like

workers = request.POST.getlist('workers_pks')

attendance_values = request.POST.getlist('attendance_values')

attendance_remarks = request.POST.getlist('attendance_remarks')

My main concern is how do I get the proper attendance_value and attendance_remarks for each corresponding workers_pks

  • 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-06-19T01:11:47+00:00Added an answer on June 19, 2026 at 1:11 am

    Use the POST attribute of the request object –

    def your_view(request):
        #...
        if attendence_value in request.POST:
            at_value = request.POST['attendence_value']
    

    However I see you’ve got lots of inputs with the same name attribute (and the browser will construct the post data using the input names as keys). You’ll need to change that. My recollection is that when django does this (with formsets), it adds a prefix to each name so that it can identify which object the input belongs with. I see you’ve already done this on the ids.

    UPDATE

    How about adding worker.pk into your name attribute –

    <input type='text' name='attendance_value{{ result.worker.pk }}'>
    

    Then in your view build the corresponding string –

    for worker in workers: 
        val_str = "attendance_value" + str(worker.pk)
        rmk_str = "attendance_remarks" + str(worker.pk)
        if val_str in request.POST:
            worker.attendance_value = request.POST['val_str']
        if mrk_str in request.POST:
            worker.attendance_remarks = request.POST['rmk_str']
    

    You might want use a different loop (maybe loop through the inputs instead). But you get the idea.

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

Sidebar

Related Questions

I have the following paint event (form) that is drawing the rectangle: void LogicSimulationViewerForm_Paint(object
I have the following code that executes when a form submits: $('input[value=enter highlight]').val(''); Essentially,
I have XML in the following form that I want to parse with PHP
I have the following form in a Struts2 JSP that contains some radio buttons.
I'm looking at some Java classes that have the following form: public abstract class
I have a following problem, I have HTML form that uploads a file with
i have the following if-clause: if(empty($var)){ $errors[]=Failure; } this is for a form that
I have a form that takes the following inputs: Name: IBM Surface(in m^2): 9
I have a simple html form that looks like the following <form action=search.php method=get>
I have the following mark up of a div that contains a form. The

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.