我没有通过模型传递元组值

时间:2019-05-08 15:15:10

标签: python django django-rest-framework

亲爱的如何在模型字段[pro_drive_name]中添加元组数据(EMPTY_CHOICES)?我正在传递此值,但未在管理页面中显示 从django.db导入模型

从django.contrib.auth.models导入用户

import os,string
drives_a = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')]
list_with_tuples = [(x, x) for x in drives_a]
EMPTY_CHOICES = [('', 'All')] + list_with_tuples
class pro_drive(models.Model):
pro_drive_name = models.CharField(max_length=2,choices=EMPTY_CHOICES)
def __str__(self):
    return self.pro_drive_name
class pro_fol(models.Model):
pro_drive = models.ForeignKey(pro_drive, on_delete=models.CASCADE)
def __str__(self):
    return self.pro_drive_name

   class Person(models.Model):
pro_drive = models.ForeignKey(pro_drive, on_delete=models.SET_NULL, null=True,choices=EMPTY_CHOICES)
pro_fol = models.ForeignKey(pro_fol, on_delete=models.SET_NULL, null=True)
def __str__(self):
    return self.pro_drive

0 个答案:

没有答案