django管理员为什么我的ForeignKey不显示?

时间:2016-10-21 09:50:40

标签: django admin foreign-key-relationship selected display

在django管理页面中,它在IDC上有默认值,但在编辑页面中,它不显示。什么方法可以得出它? one image

室温 two image

class IDC(models.Model):
      uuid = UUIDField(auto=True, primary_key=True)
      name = models.CharField(max_length=64,verbose_name=u'机房名称')

class Server(models.Model):
      idc = models.ForeignKey(IDC, blank=True, null=True, verbose_name=u'机房', on_delete=models.SET_NULL)

class ServerAdmin(admin.ModelAdmin):
      model = models.Server
      exclude = ('memo',)

1 个答案:

答案 0 :(得分:0)

虽然您未在idc模型中为Server字段设置默认值,但在创建新对象时,这不会显示在管理员中。只有在编辑现有对象时才会显示它。要在管理员中为此字段设置默认值,请在idc模型中为Server字段设置默认值。