在试图强制将输入数据格式化为大写时,我收到属性错误 " NoneType 对象没有属性条 " 。
class PostPageForm(ModelForm):
class Meta:
model = PostPage
def clean(self):
return dict([(k, v.strip().upper()) for k, v in self.cleaned_data.items()])
和我的模型:
class PostPage(models.Model):
client = models.CharField(max_length=50, choices=CLIENT_CHOICES)
job_number = models.CharField(max_length=30, unique=True, blank=False, null=False)
job_name = models.CharField(max_length=64, unique=False, blank=False, null=False)
page_type = models.CharField(max_length=50, default= POST )
create_date = models.DateField(("Date"), default=datetime.date.today)
contact = models.ForeignKey(UserProfile)
contact2 = models.ForeignKey(UserProfile, related_name= + , blank=True, null=True)
contact3 = models.ForeignKey(UserProfile, related_name= + , blank=True, null=True)
contact4 = models.ForeignKey(UserProfile, related_name= + , blank=True, null=True)
def __unicode__ (self):
return u %s %s %s % (self.client, self.job_number, self.job_name)
class Admin:
pass
class Meta:
permissions = (
( view_postpage , View postpage ),
)
我认为格式代码中“清洁”方法的重置需要根据模型的回报值进行重新配置。 我只是不知道该如何改变。