Forgive this question if the answer is overly obvious; but I have not yet figured it out. I want to use the
horizontal M2M widget from the admin interface in my own template. The model looks like something this:
class Foo(models.Model):
bars = models.ManyToManyField(Bar, filter_interface=models.
HORIZONTAL)
My views.py looks something like this:
def myView(request, object_id):
foo = Foo.objects.filter(id=object_id)[0]
FooForm = form_for_instance(foo)
form = FooForm()
rc = template.RequestContext(request)
return render_to_response('path/to/mytemplate.html', {'form': form}, rc)
And my template includes a line like:
<p><label for="id_bars">Bars:</label> {{ form.bars }}</p>
While the model alone is sufficient to produce a
horizontal filter in the admin interface, in my template all it displays is a basic HTML select multiple list.
I suspect the answer lies in decorating the widget rendered by {{ form.bars }} with a class or id so the Javascript knows to beautify it, but I am not sure how to do so.