E
E
Evgeny Zhukov2021-03-09 18:27:12
Django
Evgeny Zhukov, 2021-03-09 18:27:12

How to remake ManyToManyField for more convenient multiple selection?

Good afternoon! I'm new and learning Django, building a project in the process.
The question arose of how to make a more convenient multiple choice of the ManyToManyField type within the framework of the standard administrative panel, i.e. in the model, I need to select, for example, Actors, while there are 5-6 of them - it’s convenient when there will be, for example, 10,000 people - this is PPV + no search when choosing a value.

How can I pass this field so that it can be searched when entering the name of a multiple choice value?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeniy Zhukov, 2021-03-09
@QbicART

Now it's like this:

spoiler
6047945eaf9ac965951155.png

And I would like to bring it to something like this format with the ability to search and select multiple values.
spoiler
6047947ede0c0990625823.png

D
django-developer, 2021-03-11
@django-developer

Look in the admin panel for the "autocomplete_fields" field.
Description in documentation: https://docs.djangoproject.com/en/3.1/ref/contrib/...
example:

class QuestionAdmin(admin.ModelAdmin):
    ordering = ['date_created']
    search_fields = ['question_text']

class ChoiceAdmin(admin.ModelAdmin):
    autocomplete_fields = ['question']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question