Django Admin:编辑视图根本不显示任何字段

时间:2018-03-23 08:48:19

标签: python django django-admin

我在新的Django 1.8应用中定义了几个模型。

当我访问Django Admin时,list view(每个对象实例看到一行的表)运行正常。

令我惊讶的是,当我点击任何NSGateway项并输入edit or create page时,没有字段;只需Save按钮。

这怎么可能?所有NSGateway字段都显示为list view中的列。但edit view显示没有字段!

这些是模型:

from django.db import models


class Enterprise(models.Model):
    enterprise_id = models.CharField(max_length=40, primary_key=True)
    description = models.CharField(max_length=500, null=True)
    name = models.CharField(max_length=500)
    creationDate = models.DateTimeField()
    lastUpdatedDate = models.DateTimeField()

    def __unicode__(self):
        return self.description


class NSGateway(models.Model):
    nsgateway_id = models.CharField(max_length=40, primary_key=True)
    creationDate = models.DateTimeField()
    description = models.CharField(max_length=500, null=True)
    lastUpdatedDate = models.DateTimeField()
    personality = models.CharField(max_length=50)
    name = models.CharField(max_length=500)
    # Each NSG belongs to 1 and only 1 Enterprise.
    # Thus, when we delete de Enterprise, we delete its NSG
    enterprise = models.ForeignKey(Enterprise, on_delete=models.CASCADE)

    def __unicode__(self):
        return self.description

这是相应的admin.py

from django.contrib import admin

from flexwan_import.models import Enterprise, NSGateway


class EnterpriseAdmin(admin.ModelAdmin):
    list_display = ('enterprise_id', 'name', 'description', 'creationDate',
                    'lastUpdatedDate')
    search_fields = ['enterprise_id', 'description']


class NSGatewayAdmin(admin.ModelAdmin):
    list_display = ('nsgateway_id', 'name', 'description', 'creationDate',
                    'lastUpdatedDate')
    search_fields = ['nsgateway_id', 'description']


admin.site.register(Enterprise, EnterpriseAdmin)
admin.site.register(NSGateway, NSGatewayAdmin)

0 个答案:

没有答案