Python Django get text函数导致尝试保存未更改的内联线

Python Django get text函数导致尝试保存未更改的内联线,python,django,validation,admin,Python,Django,Validation,Admin,因此,我有这样一个场景,当我将Translation get text函数(“from django.utils.Translation import ugettext as”)添加到我的模型中时。当我试图保存记录时,在未更改的内联记录的所有“数字”字段上都会出现“此字段是必需的错误” 不应保存未更改的行,但当我添加此库的导入时,它会尝试在我的管理页面中保存这些未更改的行 谢天谢地,因为数字不能为空,所以它会中止保存。但是客户也不能使用他的系统 我看到了一些django罚单,但我不明白为什么ge

因此,我有这样一个场景,当我将Translation get text函数(“from django.utils.Translation import ugettext as”)添加到我的模型中时。当我试图保存记录时,在未更改的内联记录的所有“数字”字段上都会出现“此字段是必需的错误”

不应保存未更改的行,但当我添加此库的导入时,它会尝试在我的管理页面中保存这些未更改的行

谢天谢地,因为数字不能为空,所以它会中止保存。但是客户也不能使用他的系统

我看到了一些django罚单,但我不明白为什么get text函数会引起问题。下面是导致错误的model.py和admin.py脚本

model.py和admin.py脚本正常工作,并成功地将数据库条目保存在admin网页中

admin.py

#admin.py
from django.contrib import admin
# Register your models here.
from simulation.models import parts, repair_jobs

class partsInline(admin.TabularInline):
    model = parts

class repair_jobsAdmin(admin.ModelAdmin):
    inlines = [partsInline]

admin.site.register(repair_jobs, repair_jobsAdmin)
#model.py
from django.db import models
# Create your models here.

class repair_jobs(models.Model):
    model = models.CharField(max_length = 100)
    customer = models.CharField(max_length = 100)

    def __unicode__(self):
        return "%s, %s" %(self.customer, self.model)

class parts(models.Model):
    job = models.ForeignKey(repair_jobs)
    number = models.CharField(max_length = 100, blank = False)

    qty = models.DecimalField(max_digits = 5, decimal_places = 2, default = 1.00, blank = False, null = False)
    cost = models.DecimalField(max_digits = 5, decimal_places = 2, default = 0.00, blank = True, nulll = True)
    description = models.CharField(max_length = 100, blank = True)

    def __unicode__(self):
        return "%s: %s, %s" % (self.job, self.number, self.qty)
model.py

#admin.py
from django.contrib import admin
# Register your models here.
from simulation.models import parts, repair_jobs

class partsInline(admin.TabularInline):
    model = parts

class repair_jobsAdmin(admin.ModelAdmin):
    inlines = [partsInline]

admin.site.register(repair_jobs, repair_jobsAdmin)
#model.py
from django.db import models
# Create your models here.

class repair_jobs(models.Model):
    model = models.CharField(max_length = 100)
    customer = models.CharField(max_length = 100)

    def __unicode__(self):
        return "%s, %s" %(self.customer, self.model)

class parts(models.Model):
    job = models.ForeignKey(repair_jobs)
    number = models.CharField(max_length = 100, blank = False)

    qty = models.DecimalField(max_digits = 5, decimal_places = 2, default = 1.00, blank = False, null = False)
    cost = models.DecimalField(max_digits = 5, decimal_places = 2, default = 0.00, blank = True, nulll = True)
    description = models.CharField(max_length = 100, blank = True)

    def __unicode__(self):
        return "%s: %s, %s" % (self.job, self.number, self.qty)
上述代码成功执行,按下“保存”键后,即可成功保存数据库

但是以下代码失败

model.py和admin.py脚本不起作用,保存数据库时会导致错误““此字段是必需的” model.py:

 #model.py
 from django.db import models
 from django.utils.translation import ugettext as _
 # Create your models here.

class repair_jobs(models.Model):
    model = models.CharField(max_length = 100)
    customer = models.CharField(max_length = 100)

    def __unicode__(self):
        return "%s, %s" %(self.customer, self.model)

class parts(models.Model):
    job = models.ForeignKey(repair_jobs)
    number = models.CharField(max_length = 100, blank = False)
    qty = models.DecimalField(_("quantity"), max_digits=3, decimal_places=0, default="1",     blank=False, null=False, help_text=_("How many are needed?") 
    cost = models.DecimalField(_("cost price"), max_digits=7, decimal_places=2, blank=True,   null=True, default="0", help_text=_("Price paid per unit") )
    description = models.CharField(max_length = 100, blank = True)

    def __unicode__(self):
        return "%s: %s, %s" % (self.job, self.number, self.qty)
admin.py脚本没有从上面的代码更改,因此使用与上面相同的admin.py脚本会出现错误“此字段是必需的”

唯一的区别是我在一种情况下使用翻译,而不是在另一种情况下使用翻译

当我单击“保存”时,是否知道为什么会发生此错误

以下是我发现的django罚单的链接,该罚单可能与上述问题有关:

注意:我使用的是Django1.6和Python2.7