tthheemmaannii
tthheemmaannii

Reputation: 349

Native way to preview results in Django?

I have a django app running(frontend is vanilla everything) and it has a search function. I would like for users to see a preview dropdown of search results while typing so that they can know if there will be results without having to complete the search, to increase UX. Is there a django package or a native django method to do this? And what is this called?

Upvotes: 0

Views: 54

Answers (1)

Ranu Vijay
Ranu Vijay

Reputation: 1297

By default don't show any data on the dropdown, let user type something and then fetch the data based on user input, the filter at backend may be something like -

MyModel.objects.filter(field__startswith=user_typed_value)

Now you will have to fetch the data based on each letter (keystroke) that the user types, again this is not a very good design, as it will do a lot of database queries so use DebounceValue. you can read more about this.

Also you can read more about Autocomplete UI component.

Also select max 10 - 12 objects on the filter query. (a rough estimate)

Upvotes: 1

Related Questions