Rich Article Select

Example Overview

The Rich Article Select example showcases an advanced implementation of django_tomselect that enriches the selection interface with a highly detailed, visually appealing dropdown. This example is perfect for scenarios where users need to search for and select articles based on multiple attributes such as title, authors, categories, word count, and completion progress.

The options in the dropdown are rendered with custom HTML structures that include author avatars, status badges, freshness indicators, category tags, and progress bars. This detailed metadata provides editors with a comprehensive overview of each article, making it easier to identify and select the right content.

Objective:

  • Enhance the article selection experience with a detailed, visually rich dropdown interface.

  • Demonstrates advanced django_tomselect features like custom rendering for options and selected items.

Use Case:

  • Editorial platforms where editors need to browse articles with detailed information before selection.

  • Project management tools with tasks that have multiple attributes to display in dropdowns.

Visual Examples

Screenshot: Rich Content Article Select Options Screenshot: Rich Content Article Select Item


Key Code Segments

Forms

The form uses a TomSelectModelChoiceField with advanced rendering configurations. The TomSelectConfig object includes custom HTML templates for rendering options and selected items, allowing detailed metadata to be displayed in the dropdown.

The option template is included as a multiline string within the render attribute of the attrs dictionary. It uses JavaScript template literals to define the structure of each option, including author avatars, status badges, category tags, and progress bars.


Templates

The field is rendered in the form with minimal configuration, and custom rendering is handled in the TomSelectConfig. A key is provided to aid in understanding the custom rendering styles.


Autocomplete Views

The autocomplete-rich-article endpoint processes user queries and retrieves rich article data. The view includes custom search logic, queryset annotations, and result formatting to provide detailed metadata for each article.


Design and Implementation Notes

Key Features

  • Custom Rendering: The attrs["render"] configuration allows defining unique HTML structures for dropdown options and selected items.

  • Dynamic Attributes: Supports displaying progress bars, badges, and tags to highlight article attributes visually.

  • Preloading: The dropdown is preloaded when focused to enhance user experience. If the preload option is disabled, the dropdown will load results only after the user starts typing.