我如何从Django的mysql中检索数据,以便在其中也可以更新它的模式中显示?

问题描述 投票:0回答:1

我需要做的是单击视图模式按钮后,它将显示信息,然后还有一个按钮可以对其进行更新。有人可以建议我这样做是最好的。谢谢。Models.py

class Employee(models.Model):
first_name = models.CharField(max_length=100, blank=True, null=True)
last_name = models.CharField(max_length=100, blank=True, null=True)
middle_name = models.CharField(max_length=100, blank=True, null=True)
userid = models.CharField(max_length=45, blank=True, null=True)
email_address = models.CharField(max_length=100, blank=True, null=True)

我还没有views.py(不知道从哪里开始)

模式代码:

{% for employee in employees %}

            <div class="modal fade" id="employee.employee_id_{{ employee.employee_id }}" tabindex="-1" role="dialog" style="display: none; overflow: auto;" aria-hidden="true" data-backdrop="static">
                <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" >Employee</h5>
                            <button type="button" class="close" modalid="referral_modal" id="close_referral" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                        </div>
                        <div class="modal-body" style="overflow: auto">
                            <div class="col-md-15">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-12">
                                        <h4>Your Profile</h4>
                                        <hr>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <form>
                                          <div class="form-group row">
                                            <label for="username" class="col-4 col-form-label">User Name*</label>
                                            <div class="col-8">
                                              <input id="username" name="username" placeholder="{{ employee.userid}}" class="form-control here" required="required" type="text">
                                            </div>
                                          </div>
                                          <div class="form-group row">
                                            <label for="name" class="col-4 col-form-label">First Name</label>
                                            <div class="col-8">
                                              <input id="name" name="name" placeholder="{{ employee.first_name}}" class="form-control here" type="text">
                                            </div>
                                          </div>
                                            <div class="form-group row">
                                            <label for="text" class="col-4 col-form-label">Middle Name*</label>
                                            <div class="col-8">
                                              <input id="text" name="text" placeholder="{{ employee.middle_name}}" class="form-control here" required="required" type="text">
                                            </div>
                                          </div>
                                          <div class="form-group row">
                                            <label for="lastname" class="col-4 col-form-label">Last Name</label>
                                            <div class="col-8">
                                              <input id="lastname" name="lastname" placeholder="{{ employee.last_name}}" class="form-control here" type="text">
                                            </div>
                                          </div>                                                              
                        <div class="modal-footer">
                            <button name="submit" type="submit" class="btn btn-primary">Update</button>
                            <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="">Cancel</button>
                        </div>

                </div>
                    </div>
                </div>
            </div>
        </div>
    {% endfor %}
    {% endblock %}

MySQL DB

python mysql django modal-dialog
1个回答
0
投票

您可以将标签设为只读。例:

然后在javascript中单击“更新按钮”,就可以再次对其进行编辑。document.getElementById(“ name”)。readOnly = false;

© www.soinside.com 2019 - 2024. All rights reserved.