核心:obj.get_字段名_display

1、定义module 数据结构:

class msg(models.Model):
     
    choice = (
        (1, '技术部'),
        (2, '行政'),
        (3, '人事'),
        (4, "财务"),
    )
    group = models.IntegerField(choices=choice)

 2、views 视图:

def test(request):
    info = models.msg.objects.all()
    return render(request,"ceshi.html",{"info":info})

 3、在前端显示:

<div>
        {% for i in info %}
            <p><span>{{ i.get_group_display }}</span></p>
        {% endfor %}
</div>

 

相关文章:

  • 2021-06-22
  • 2021-12-07
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2021-12-06
  • 2022-01-07
相关资源
相似解决方案