开发者社区> 问答> 正文

mysql表如何获得关于该id的名称方面?

在我的项目中,我的操作很复杂,因此当我选择部门时,我保存该项目的ID,并绑定到表以显示插入的记录,因此当我绑定部门时,我想绑定该部门的名称而不是该ID。请帮助我。

模型

class Department(models.Model):
  ACTIVE = 1
  INACTIVE = 2
  DELETED = 3
  STATUS_CHOICES = (
    (ACTIVE, 'active'),
    (INACTIVE, 'inactive'),
    (DELETED, 'deleted'),
  )
  department_id = models.AutoField(primary_key=True)
  department_name = models.CharField(max_length=30, null=False)
  created_on = models.DateTimeField(auto_now_add=True,  null=False)
  created_by = models.CharField(max_length=100, null=False)
  modified_on = models.DateTimeField(auto_now_add=True)
  modified_by = models.CharField(max_length=100)
  status = models.CharField(max_length=10, null=False, choices=STATUS_CHOICES)

 objects = UserManager()

  class Meta:
    managed = True
    db_table = "ht_department"

  def __str__(self):
    return self.department_id

表格

class EmpForm(ModelForm):
  class Meta:
      model = Employee
      fields = ["employee_id", "Name", "designation", "department_id", "manager_id", 
       "date_of_joining","date_of_birth", "location_id", "email", "contact_number",                  
         "password", "created_by", "modified_by", "status",   "user_type"]



class dept(ModelForm):
   class Meta:
      model = Department
      fields = ["department_id", "department_name", "created_by", "modified_by", "status"]


class EmpLoc(ModelForm):
  class Meta:
    model = Location
    fields = ["location_id", "location_name", "created_by", "modified_by", "status"]

html

<tbody id="myTable">
                {% for employee in employees %}

                <tr>
                    <td>{{ employee.employee_id}}</td>
                    <td>{{ employee.Name}}</td>
                    <td>{{ employee.designation}}</td>
                    <td>{{ employee.department_id}}</td>
                    <td>{{ employee.manager_id}}</td>
                    <td>{{ employee.location_id}}</td>
                    <td>

                        <a href="#editEmployeeModal" class="edit" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Edit"></i></a>
                        <a href="#deleteEmployeeModal" class="delete" data-toggle="modal"><i class="material-icons" data-toggle="tooltip" title="Delete"></i></a>
                    </td>
                </tr>
          {% endfor %}


            </tbody>

展开
收起
几许相思几点泪 2019-12-05 15:01:04 315 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
搭建电商项目架构连接MySQL 立即下载
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载

相关镜像