开发者

Django: custom ManyToMany field in form

I want to display a ManyToMany field into a widget/Html-form which the user can delete by X-ing items using jquery.

class user_profile:
  links = ManyToManyField(...)

Then when I render the formset it would be something like:

<form>
  <input type="checkbox" name="id" value="link_to_dele开发者_Go百科te_item_using_ajax_call" />
  ....
  ....
</form>

Is there any existing? If not, how should I code it? ModelForm? Custom Form?

Thanks!


The best place for this is usually a custom Widget class. For example you could subclass CheckboxSelectMultiple and then use your custom widget in your form classes for relevant form fields.

The widget can automatically include the required JS/CSS by specifying it in the internal Media class

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜