为什么django admin没有显示ImageField的“当前”值?

时间:2017-12-20 04:30:39

标签: python django linux

在其他计算机上部署django应用程序时遇到问题。在我的本地机器上工作正常,但在linux机器上没有显示(当前)ImageField的当前值。两种环境都有django 1.11。

模特:

class Company(models.Model):
    class Meta:
        verbose_name = ("Empresa")
    name = models.CharField(max_length=500, verbose_name="nombre")
    nit = models.CharField(max_length=50, verbose_name="nit")
    address = models.CharField(max_length=500, verbose_name="dirección", blank=True, null=True)
    telephone = models.CharField(max_length=15, verbose_name="teléfono", blank=True, null=True)
    cellphone = models.CharField(max_length=15, verbose_name="celular", blank=True, null=True)
    legal_representative = models.CharField(max_length=500, verbose_name="representante legal", blank=True, null=True)
    photo = models.ImageField(upload_to='company/img', verbose_name="imagen", blank=True, null=True)
    photo_thumbnail1 = models.ImageField(upload_to='company/img', verbose_name="imagen 250x250", blank=True, null=True)

    def __str__(self):
        return self.name

    def __unicode__(self):
        return self.name

管理员:

class CompanyAdmin(admin.ModelAdmin):
    exclude = ('photo_thumbnail1',)
    list_display = ('id','name', 'nit', 'address','telephone','cellphone','legal_representative',)

    def render_change_form(self, request, context, *args, **kwargs):
        # Just to show the photo url while rendering
        print('rendering')
        print(vars(kwargs['obj']))
        if kwargs['obj'].photo:
            print(kwargs['obj'].photo.url)
        if kwargs['obj'].photo_thumbnail1:
            print(kwargs['obj'].photo_thumbnail1.url)
        return super(CompanyAdmin, self).render_change_form(request, context, args, kwargs)

在我的本地机器中,我可以看到以前保存时Photo的当前值: Change form in local machine

在linux机器中,它没有显示当前值,就好像没有为该字段保存图像一样。但是我确保通过在控制台中打印来渲染时获得的值是:

enter image description here

enter image description here

如果您对我能做什么有任何想法,请您深深体会。

0 个答案:

没有答案