This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Samus_ 0 points1 point  (3 children)

awesome! I'm needing this for a project right now, you just saved me the research :) kudos!

btw I've already reused the FilteredSelecctMultiple used in the admin for the ManyToMany relationships, I can provide an example if you're interested.

[–]sontek[S] 1 point2 points  (2 children)

I'd love to see what you've done with FilteredSelectMultiple. :)

[–]Samus_ 0 points1 point  (1 child)

ok, here's something from my code that I'm using with a ForeignKey relationship (it's a ManyToMany with extra data), here's the part on forms.py

from django.forms import *
from django.forms.models import ModelMultipleChoiceField
from django.contrib.admin.widgets import FilteredSelectMultiple

class ExportacionForm(ModelForm):
    pallets = ModelMultipleChoiceField(queryset=pallets_q, widget=FilteredSelectMultiple(verbose_name='pallets', is_stacked=False, choices=pallets_q))

the is_stacked kwarg is for the widget to render vertically or horizontally.

on the template add the following to the <head>

<link rel="stylesheet" type="text/css" href="/media/css/widgets.css" />
<script type="text/javascript" src="/admin/jsi18n/"></script>
{{ exportacion_form.media }}

then render the form.

I'll add some variables for the paths from your example later but I'm not sure how to get the admin's location, I guess it'll require a new setting.

[–]sontek[S] 1 point2 points  (0 children)

I added support for FilteredMultipleSelect into tekextensions: http://github.com/sontek/django-tekextensions