I created the model and set the primary key. How to show model primary keys in Django templates

28 Views Asked by At

I am new to Django, I want to display table data to Modal html form but it always shows the 1st record on Modal form. For e.g. in the image below, I have clicked on 43. TEST - 4, 43 is the primary key, I want to display the primary key in the Modal title, But the Modal title shows the primary key 41 which is 1st record.

HTML code

<div class="container">
        <h3 class="pt-5 text-center">Waara List as of - {% now "jS F Y" %}</h3><br>
        <div class="row">
            <h3><pre color="green">&nbsp;&nbsp;Pending Waara's                                          Waara already given</pre></h3   >
           
            <div class="col-md-7 col-lg-6.5" style="height: 600px; overflow: scroll;">
                <!-- List of all the tasks for the day -->
                {% for i in dictTask %}
                <div class="card m-1">
                    <div class="card-body">
                        {{i.pk}} - {{i.firstname}} - {{i.lastname}}  - {{i.phonenumber}}
                        <span style="position: relative; float: right;">
                            <a href="{% url 'markasdonename' i.pk %}" class="btn btn-success" data-toggle="modal" data-target="#exampleModal"><i class="fa fa-check"></i> Mark as Done</a>
                          
<!-- Modal -->
                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                    <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel">PRIMARY KEY {{i.pk}} </h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                            <input type="text" name="firstname" class="form-control" placeholder="First Name"  value="{{ i.firstname}}"><br>
                        </button>
                        </div>
                        <div class="modal-body">
                        ...
                        </div>
                        <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="button" class="btn btn-primary">Save changes</button>
                        </div>
                    </div>
                    </div>
                </div>
                        </span>
                    </div>
                </div>
                {% endfor %}
            </div>
          

I was expecting correct Primary Key

0

There are 0 best solutions below