autocomplete_fields显示错误“ ValueError:int()的无效文字,基数为10:'Empty'”

时间:2018-09-24 05:56:10

标签: django django-models

我的自动填充功能正在运行,但是有问题 这是admin.py

encodeText() {
 this.barcode.encode(this.barcode.Encode.TEXT_TYPE,this.barcodeData).then((encodedData) => {
  this.encodedData = encodedData;

  }, (err) => {
  console.log("Error occured : " + err);
});

这是我的模特。py

from django.contrib import admin
from pages.models import Ipaddress, DeviceGroup, Location,Department,Comment
from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter


class DepartmentAdmin(admin.ModelAdmin):
    search_fields = ['name']

class LocationAdmin(admin.ModelAdmin):
    search_fields = ['description']   


class IpaddressAdmin(admin.ModelAdmin):
        prepopulated_fields = {'slug': ('ipaddress',)}
        search_fields = ['ipaddress','location','department',]   

        list_display = ('ipaddress', 'machinename', 'user', 'department','location','updated',)

        list_display_links =('ipaddress', 'machinename', 'user', 'department','location','updated',)        

        autocomplete_fields = ['location','department',]

        list_filter = (
        ('user', DropdownFilter),
        ('department', RelatedDropdownFilter),
        ('location', RelatedDropdownFilter),

    )

当我尝试添加新的IP地址时,它向我显示HTML页面中的以下错误

enter image description here

在控制台中,它显示以下错误:

class Ipaddress(models.Model):
    ipaddress=models.CharField("Ip Address",max_length=20)
    slug = models.SlugField(unique=True)
    machinename=models.CharField("Machine Name",max_length=500)
    user=models.CharField("User",max_length=200)
    department= models.ForeignKey("Department", on_delete=models.CASCADE,default='Empty')
    location= models.ForeignKey("Location", on_delete=models.CASCADE)
    updated = models.DateField("Date Updated",null=True)
    note =models.TextField()
    class Meta:
       verbose_name = 'IP Management'

    def __str__(self):
        return self.ipaddress[:50]

除了添加类Meta之外,我没有进行任何重大更改。其他所有工作正常的模型(仅此一种)在尝试添加新记录时显示错误。

ValueError: invalid literal for int() with base 10: 'Empty' 有效 但autocomplete_fields = ['location',]不起作用

0 个答案:

没有答案