开发者

Django: Put multiple widgets/fields into one field

I'm making a form to let users edit their photo gallery. So when I show the form I need 2 fields/widget pe开发者_如何学编程r photo.

For each photo there will be one

CheckBox(label='Delete photo', value=<Id of photo>) and one RadioSelect(label='Set as cover image', value=<Id of photo>)

In the form class I guess I should put something like this in the __init__:

for image in images:
    #make a checkbox widget
    #make a radio select
    #store the url of the image
    self.fields[..] = gallery_field_widget

I would prefer to put as much code in the form class instead of the template. I've played around with MultpleSelect widget but I can't figure out how to iterate through it together with the rest of the widgets.. and help on this?


This isn't two widgets per field, this is two fields per form and one form per instance. For that we have formsets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜