#How to implement search and select multiple

18 messages · Page 1 of 1 (latest)

still sierra
#

I'm struggling to implement a search and select multiple for this field. I have a list of locations of all countries and their states/provinces. I need to be able to search and select multiple items without having to scroll and ctrl+click each time. My locations are in a Location model and that is used in my PlantSpecies class

class PlantSpecies(models.Model):
    distribution = models.ManyToManyField(Location, blank=True)

How can I change this from a scroll with no search, to a scroll with a search? I've tried about a dozen different items with django select 2, the filtered select multple, and others. This is my current form which does allow me to select multiple via ctrl+click and they do save, but it's super tedious to find what I need.

class PlantSpeciesForm(forms.ModelForm):
    distribution = forms.ModelMultipleChoiceField(
        queryset=Location.objects.all(),
        widget=FilteredSelectMultiple("distribution", is_stacked=False),
        required=False,
    )

    class Meta:
        model = PlantSpecies
        fields = {'genus', 'species_name', 'distribution', 'year_discovered', 'alt_low', 'alt_high'}  # replace 'name' with your actual fields
    
    class Media:
        css = {
            'all': ('/static/admin/css/widgets.css',),
        }
        js = ('/admin/jsi18n',)
        
    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        super().__init__(*args, **kwargs)

https://imgur.com/a/CmFuAHB

What can I do different? What other information would be helpful for you to help me?

warm river
#

What is FilteredSelectMultiple widget?

#

That's django admin widget it seems not django-select2

still sierra
warm river
#

I mean what you described sounds just like dj-select2 model multiple select

#

It's a list of items with searching input

still sierra
#

With searching and multi-select? I need to be able to search and add countries/states. So sometimes I'm adding 6-20 different locations, and my list of locations is about 5,300 items large, so a scrolling box or a checkbox won't work.

#

I tried using it and the only way I could get it to work was to ctrl+click and scroll to find what I needed. The search function never worked for me.

warm river
#

Yes it's an area of all selected items displayed as inlines with remove button and new added via text input with dynamic drop down with suggestions

#

Can't make a screencap now from project I'm using it because it's in admin and I can't login from this device

still sierra
#

That's exactly what I need. Any ideas on what I can change in my code to get that to work?

still sierra