Django管理员字段显示

时间:2018-06-11 10:26:30

标签: django django-models django-forms django-admin

这是我在admin.py中注册的设备:

@admin.register(Device)
class DeviceAdmin(admin.ModelAdmin):
  search_fields = ["device_type","serial_number","in_use_by","brand","model","type_number","mac_address"]
  list_display = ("device_type","serial_number","in_use_by","brand","model","type_number","mac_address","invoice",)
  list_filter = ("device_type","in_use_by","brand",)

这是models.py

中的设备型号
class Device(models.Model):
    device_type         = models.ForeignKey(DeviceType,to_field='device_type')
    serial_number       = models.CharField(max_length=200,unique=True)
    in_use_by           = models.ForeignKey(User,to_field='username')
    brand               = models.CharField(max_length=200,default="-", null=False)
    model               = models.CharField(max_length=200,default="-", null=False)
    type_number         = models.CharField(max_length=200,blank=True,null=True, default = None)
    mac_address         = models.CharField(max_length=200,blank=True,null=True, default = None)
    invoice             = models.BinaryField(blank=True)

这是我在forms.py

中的表单类
class ReturnForm(forms.ModelForm):
    class Meta:
        model = Device
        fields = "__all__"
        widgets = {"device_type": forms.Select(attrs={"class":"custom-select col-sm-4"})}
        exclude = ("serial_number","in_use_by","brand","mac_address","type_number","model","invoice",)

现在,当我查看我的管理面板时,发票会在面板中显示为列名。但是,当我通过单击更详细地查看对象时,不会显示发票字段。

outer view

inner detailed view

发生了什么问题? 我该如何解决这个问题? 请求立即帮助。

1 个答案:

答案 0 :(得分:0)

BinaryField不能在ModelForm中使用,因此我怀疑它也无法在管理员的更改表单中显示。您可以在此处查阅BinaryField的文档:https://docs.djangoproject.com/en/2.0/ref/models/fields/#binaryfield

另请注意有关滥用BinaryField将文件存储在数据库中的警告。