@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",)
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)
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",)
现在,当我查看我的管理面板时,发票会在面板中显示为列名。但是,当我通过单击更详细地查看对象时,不会显示发票字段。
发生了什么问题? 我该如何解决这个问题? 请求立即帮助。
答案 0 :(得分:0)
BinaryField
不能在ModelForm中使用,因此我怀疑它也无法在管理员的更改表单中显示。您可以在此处查阅BinaryField的文档:https://docs.djangoproject.com/en/2.0/ref/models/fields/#binaryfield。
另请注意有关滥用BinaryField将文件存储在数据库中的警告。