{"action":"created","issue":{"url":"https://api.github.com/repos/sshwsfc/xadmin/issues/470","repository_url":"https://api.github.com/repos/sshwsfc/xadmin","labels_url":"https://api.github.com/repos/sshwsfc/xadmin/issues/470/labels{/name}","comments_url":"https://api.github.com/repos/sshwsfc/xadmin/issues/470/comments","events_url":"https://api.github.com/repos/sshwsfc/xadmin/issues/470/events","html_url":"https://github.com/sshwsfc/xadmin/issues/470","id":277232487,"number":470,"title":"ImageField 保存问题","user":{"login":"191801737","id":20100667,"avatar_url":"https://avatars2.githubusercontent.com/u/20100667?v=4","gravatar_id":"","url":"https://api.github.com/users/191801737","html_url":"https://github.com/191801737","followers_url":"https://api.github.com/users/191801737/followers","following_url":"https://api.github.com/users/191801737/following{/other_user}","gists_url":"https://api.github.com/users/191801737/gists{/gist_id}","starred_url":"https://api.github.com/users/191801737/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/191801737/subscriptions","organizations_url":"https://api.github.com/users/191801737/orgs","repos_url":"https://api.github.com/users/191801737/repos","events_url":"https://api.github.com/users/191801737/events{/privacy}","received_events_url":"https://api.github.com/users/191801737/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-11-28T02:00:56Z","updated_at":"2017-12-22T11:05:00Z","closed_at":null,"author_association":"NONE","body":"\r\n\r\npython==3.5.4, django==1.11.7 \r\n\r\nmodels.py 中的一个表 然后分别注册到 xadmin 和admin 中\r\n```\r\nclass Banner(models.Model):\r\n    title = models.CharField(max_length=100, verbose_name=u'标题')\r\n    image = models.ImageField(max_length=100, upload_to='banner/%Y/%m', verbose_name=u'轮播图')\r\n    url = models.URLField(max_length=200, verbose_name=u'访问地址')\r\n    index = models.IntegerField(default=100, verbose_name=u'顺序')\r\n    add_time = models.DateTimeField(default=datetime.datetime.now, verbose_name=u'添加时间')\r\n```\r\n添加一条测试数据  然后点开 不做任何操作，再次点击保存\r\n就会提示：请选择一个文件，\r\n\r\n![11](https://user-images.githubusercontent.com/20100667/33298673-9b90d974-d422-11e7-9a16-5adc4c940db7.jpg)\r\n\r\n\r\n用django自带的admin  再次点击保存就不会有这个问题，大神们帮忙看看 是不是bug呀  \r\n\r\n![22](https://user-images.githubusercontent.com/20100667/33298720-f1d4a0ae-d422-11e7-8b39-833602817bb0.jpg)\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sshwsfc/xadmin/issues/comments/353576078","html_url":"https://github.com/sshwsfc/xadmin/issues/470#issuecomment-353576078","issue_url":"https://api.github.com/repos/sshwsfc/xadmin/issues/470","id":353576078,"user":{"login":"xianfuxing","id":18302523,"avatar_url":"https://avatars0.githubusercontent.com/u/18302523?v=4","gravatar_id":"","url":"https://api.github.com/users/xianfuxing","html_url":"https://github.com/xianfuxing","followers_url":"https://api.github.com/users/xianfuxing/followers","following_url":"https://api.github.com/users/xianfuxing/following{/other_user}","gists_url":"https://api.github.com/users/xianfuxing/gists{/gist_id}","starred_url":"https://api.github.com/users/xianfuxing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xianfuxing/subscriptions","organizations_url":"https://api.github.com/users/xianfuxing/orgs","repos_url":"https://api.github.com/users/xianfuxing/repos","events_url":"https://api.github.com/users/xianfuxing/events{/privacy}","received_events_url":"https://api.github.com/users/xianfuxing/received_events","type":"User","site_admin":false},"created_at":"2017-12-22T11:05:00Z","updated_at":"2017-12-22T11:05:00Z","author_association":"NONE","body":"经过一下午的调试，我找到问题所在，调试过程参考admin代码\r\n修改xadmin/plugins/images.py，在AdminImageWidget类的最后添加：\r\n\r\n```\r\ndef use_required_attribute(self, initial):\r\n       return super(AdminImageWidget, self).use_required_attribute(initial) and not initial\r\n```\r\n\r\n最终如下：\r\n```\r\nclass AdminImageWidget(forms.FileInput):\r\n      \"\"\"\r\n      A ImageField Widget that shows its current value if it has one.\r\n       \"\"\"\r\n    def __init__(self, attrs={}):\r\n        super(AdminImageWidget, self).__init__(attrs)\r\n\r\n    def render(self, name, value, attrs=None):\r\n        output = []\r\n        if value and hasattr(value, \"url\"):\r\n            label = self.attrs.get('label', name)\r\n            output.append('<a href=\"%s\" target=\"_blank\" title=\"%s\" data-gallery=\"gallery\"><img src=\"%s\" class=\"field_img\"/></a><br/>%s ' %\r\n                         (value.url, label, value.url, _('Change:')))\r\n        output.append(super(AdminImageWidget, self).render(name, value, attrs))\r\n        return mark_safe(u''.join(output))\r\n\r\n    def use_required_attribute(self, initial):\r\n        return super(AdminImageWidget, self).use_required_attribute(initial) and not initial\r\n```\r\n\r\n有无其他影响还未知。待深入测试。"}}
{"actor":{"display_login":"xianfuxing"}}