我试图在django cms 3.6中创建一个自定义插件,其中有一个字段可以添加多个图像。为此我创建了两个模型并使用外键将其链接
我希望space_image字段为多张图片上传字段
class SpaceModel(CMSPlugin):
space_name = models.CharField(max_length=50)
space_size = models.CharField(max_length=50)
space_image = models.FileField(upload_to="memox_images")
def __unicode__(self):
return "%s" % (self.space_name, )
class SpaceImages(models.Model):
spacemodel = models.ForeignKey(SpaceModel, default=None)
image = models.ImageField(upload_to='memox_images',
verbose_name='Image',blank="True",null="True",)
def __unicode__(self):
return "%s" % (self.spacemodel, )
class SpaceModelPlugin(CMSPluginBase):
model = SpaceModel
name = "New Space"
render_template = "space_images.html"
def render(self, context, instance, placeholder):
context.update({
'space_name' : instance.space_name,
'space_size' : instance.space_size,
'space_image':instance.space_image
})
return context
预先感谢