Skip to content

How to add a few strings for like "Select all"? #32

@Teut2711

Description

@Teut2711

Goal
To get an entry "Select all" in the search.

Problem
I have around 20 million rows in table. The Admin wants to send mail to some specific or to all users. Now he may type a phrase to search for a user or he may want to send the mail to all users. If he wants to send mail to all the users it would just be sufficient for him to select "Select all" from the field.

Code Snippet
Please provide a code snippet of your problem.



class UsersWidget(s2forms.ModelSelect2MultipleWidget):
    search_fields = [
        "email__istartswith",
        "PAN_ID__istartswith",
        "full_name__istartswith",
    ]
    empty_label = "Select all"

    def label_from_instance(self, obj):
        return obj.email

    def filter_queryset(self, request, term, queryset=None, **dependent_fields):

        return super.filter_queryset(request, term, queryset, **dependent_fields)


class MailForm(forms.Form):
    to = forms.ModelMultipleChoiceField(
        label="To",
        queryset=User.objects.all(),
        widget=UsersWidget,
    )

    subject = forms.CharField(max_length=78)
    content = QuillFormField()
    fileupload = forms.FileField()

image

A badge of this kind with text as "Select all" is required.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions