python - 我如何从 django 中的 mysql 检索数据并以模式显示,其中我也可以更新它?

标签 python mysql django modal-dialog

我需要做的是单击 View 模式按钮后,它将显示信息,然后还有一个按钮可以更新它。有人可以建议我哪一个是最好的事情吗?谢谢。 模型.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

最佳答案

您可以将标记设置为只读。 例子:

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

关于python - 我如何从 django 中的 mysql 检索数据并以模式显示,其中我也可以更新它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58722751/

相关文章:

python - 使用非阻塞 udp 读取时丢失消息

python - 从 GTK 弹出菜单中获取焦点

python - Django user.save() 在列 'is_superuser' 上失败不能为空

MySQL断言

mysql - 在没有密码提示的情况下在 Ubuntu 上安装 MySQL

django - 使用 unix 套接字时 Django ALLOWED_HOSTS 应该是什么?

python 问答游戏错误

python - 使用Numpy计算基尼系数

python - Django - 从每个组的最新日期检索对象 - PersonPhoto

django - 在不指定查找的情况下调用 prefetch_lated() 有用吗?