【发布时间】:2017-06-05 20:00:36
【问题描述】:
当我在 Admin 中打开“Placerating”条目,并在对任何字段进行更改后尝试保存它时,Django admin 在“Pic”字段上方显示“此字段是必需的”。
class Placerating(models.Model):
theplace = models.ForeignKey('ThePlace', on_delete=models.CASCADE, null=True, related_name='placeratings')
pic = models.OneToOneField('fileupload.Picture', on_delete=models.SET_NULL, null=True)
def __unicode__(self):
return self.theplace.name
class Picture(models.Model):
def set_upload_to_info(self, path, name):
self.upload_to_info = (path, name)
file = ImageField(max_length=500, upload_to=user_directory_path)
def filename(self):
return os.path.basename(self.file.name)
theplace = models.ForeignKey(ThePlace, null=True, blank=True, related_name='pictures')
def __unicode__(self):
return str(self.id)
def save(self, *args, **kwargs):
super(Picture, self).save(*args, **kwargs)
我用表单创建条目没有问题,所以我不明白为什么管理员现在会要求填写此字段。
【问题讨论】:
标签: python django model django-admin