Reputation: 6530
The default django 1.0.2 ManyToManyField widget (a multi-select) is difficult to use when there are a lot of things in the select box. Is there another widget available that gives a comma separated list of id's in a textarea? If this is not available what do I need to do to write one, and have it show up on ModelForm.as_p() and in the admin site?
Upvotes: 2
Views: 2520
Reputation:
I believe setting raw_id_fields on the manytomanyfield actually outputs a TextInput widget with a comma-separated list of ids. You may just override this in admin.py, in the corresponding ModelForm and force a TextArea widget on it.
Upvotes: 2
Reputation: 11477
If there are no existing widgets that do what you want (and I don't think there are) then you'll need to write your own. Unfortunately, the Django documentation doesn't show you how to do this, but it's not hard to figure out by looking at the source-code forms/widgets.py
copying an existing widget and modifying it.
Upvotes: 2
Reputation: 3266
In the Admin you can use filter horizontal and/or filter vertical:
class MyModelAdmin(admin.ModelAdmin):
filter_horizontal = ['many_to_many_field_name']
filter_horizontal = ['another_many_to_many_field_name']
Upvotes: 1