class IdcInfo(models.Model):
virtual_choice = (
(0, '否'),
(1, '是'),
)
idc_name = models.CharField(max_length=50, verbose_name=('机房名字'), default=u"", null=True, blank=True)
is_virtual = models.IntegerField(verbose_name=("是否云主机"), choices=virtual_choice, default=0)
class IdcAddView(View):
"""
添加 IDC 信息
"""
def get(self, request):
if request.user.is_superuser:
is_virtual_list = IdcInfo.objects.all()
print is_virtual_list
return render(request, "assets/idcadd.html", {is_virtual_list: 'is_virtual_list'})
else:
return HttpResponse("用户无权限")
前端 html 内容
{% for is_virtual_i in is_virtual_list %}
{{ is_virtual_i.get_is_virtual_choices_displa }}
{% endfor %}
option 2