Django:如何编辑附加到项目模型的图库?
我有一个“项目”模型。每个项目都有一个“画廊”,每个画廊都有“照片”。
class Project:
gallery = ForeignKey(Gallery)
class Gallery:
photos = ManyToManyField(Photo)
class Photo:
image = ImageField(...)
我想让我的用户在同一页面上编辑图库和项目。您能告诉我需要哪些组件才能实现这一目标吗?就像我应该使用哪种类型的表单以及在处理包含上传的图像等的表单时使用什么技术?
需要考虑的是,我想显示用户正在使用 html img 标签和文件标签编辑的照片,以便他替换照片。我不想要 django 的默认 m2m-widget,它只是一个多选列表。
你能帮我解决这个问题吗,因为我根本做不到。被困在这里三天了:)
I have a 'project' model. Each project has a 'gallery' and each gallery has 'photos'.
class Project:
gallery = ForeignKey(Gallery)
class Gallery:
photos = ManyToManyField(Photo)
class Photo:
image = ImageField(...)
I want to let my users edit the gallery and the project on the same page. Could you tell me what components I need to make this happen? Like which type of form I should use and what technique to use when I process the form with the uploaded images and all?
What to take into account is that I want to show the photos the user is editing with the html img-tag as well as file-tag to let him replace the photo. I don't want django's default m2m-widget which is just a multiselect-list.
Could you help me figure this out, because I simply can't. Been stuck here for three days :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 Project 作为 admin.TabularInline 来修改 Gallery 管理表单。
像这样:
You can modify your Gallery Admin form using Project as a admin.TabularInline.
Like this:
我不想使用内置的管理模块。但我使用了 django 的表单集工厂。它会让我向表单集提供查询集(即图库中的照片)。然后我必须提供一个小的定制模型表单集类,然后我认为我几乎必须手动处理表单才能将其正确链接到画廊等。
I didn't want to use the built in admin module. But I used the formset factory by django. It will let me provide a queryset to the formset (i.e the photos in the gallery). Then I had to provide a small customized model formset class, and then i the view I pretty much had to process the form manually in order to link it correct to the gallery and such..