使用Django Filer的Django 1.11图像库

时间:2017-11-14 21:22:37

标签: python django image django-filer

问题

我需要在产品页面上显示图片库。这在我们在Django 1.6时工作,但后来升级到Django 1.11(Big Process)。我现在仍然坚持如何在新环境中使用它。现在点击Add Image会弹出一个弹出窗口,我可以选择图像以及与之关联的区域(美国,加拿大,西班牙等等),但点击“保存”后弹出标题会变为{ {1}}并且永不关闭 - 图片也未添加到图库中。我上传的图像会被添加到文件管理器中的其余图像中,但不会添加到ProductGallery模型中。

我得到了什么

Django:1.11.7

Django-Filer:1.2.7

Django-Suit:0.2.25

Vanilla-Views:1.0.4

我有产品型号,这些产品与ProductGallery模型有很多关系,如下所示:

Popup closing...

ProductGallery应该容纳图像和视频,允许上传任何一个,并提供一个列表在前端进行迭代以用于显示目的。

ProductGallery 定义为:

class Product(models.Model):
    gallery = models.ManyToManyField('products.ProductGallery')

其中class ProductGallery(models.Model): limit = models.Q(app_label='media', model='image') | models.Q(app_label='media', model='video') order = models.PositiveIntegerField(default=0) content_type = models.ForeignKey(ContentType, limit_choices_to=limit) object_id = models.PositiveIntegerField(db_index=True) content_object = generic.GenericForeignKey('content_type', 'object_id') class Meta: ordering = ('order',) def __str__(self): return six.text_type(self.content_object) 定义为:(我暂时忽略视频)

media.image

我有一个像这样添加新媒体的观点:

class Image(CountryInfoModel, models.Model):
    image = FilerImageField(null=True, blank=True)

    def __str__(self):
        return str(self.image.name or self.image.original_filename)

我认为这就是所有的部分。我迷失了为什么当我点击“保存”时,图像根本没有保存到ProductGallery模型中。如果需要,我很乐意提供更多背景信息,非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

以防万一其他人遇到这个并想知道它是如何修复的。

事实证明,某些django-admin模板功能已被覆盖并导致一些问题。

具体来说,这个项目已经覆盖了保存按钮功能的部分内容。函数dismissAddRelatedObjectPopup曾被命名为dismissAddAnotherPopup

这些功能被覆盖,以提供上述ProductGallery的自定义功能。 Django去调用这个函数,但这会在弹出窗口上抛出一个错误,该错误与SelectBox相关,然后打破了正确保存模型所需的ajax调用。

希望这可以帮助将来的某个人!

相关问题