修改xadmin/plugins/images.py,在AdminImageWidget类的最后添加:
def use_required_attribute(self, initial):
return super(AdminImageWidget, self).use_required_attribute(initial) and not initial
最终如下:
class AdminImageWidget(forms.FileInput):
"""
A ImageField Widget that shows its current value if it has one.
"""
def __init__(self, attrs={}):
super(AdminImageWidget, self).__init__(attrs)
def render(self, name, value, attrs=None):
output = []
if value and hasattr(value, "url"):
label = self.attrs.get('label', name)
output.append('<a href="%s" target="_blank" title="%s" data-gallery="gallery"><img src="%s" class="field_img"/></a><br/>%s ' %
(value.url, label, value.url, _('Change:')))
output.append(super(AdminImageWidget, self).render(name, value, attrs))
return mark_safe(u''.join(output))
def use_required_attribute(self, initial):
return super(AdminImageWidget, self).use_required_attribute(initial) and not initial
来源 https://github.com/sshwsfc/xadmin/issues/470
感谢这位大神的解决方案