List and Create Articles

Example Overview

This is one of the most comprehensive examples showcasing the capabilities of django_tomselect in a real-world scenario.

The List and Create Articles example demonstrates how to integrate django_tomselect for filtering and managing articles efficiently. The “List” view enables filtering based on various attributes like edition year and word count using django_tomselect with iterables, while the “Create / Update” views facilitate adding or updating articles with fields powered by django_tomselect.

We also incorporate the filter-by and exclude-by examples into the form to demonstrate the flexibility of the plugin.

Objective:

  • Showcase dynamic filtering in the article list view using TomSelectChoiceField and TomSelectModelChoiceField.

  • Demonstrate a feature-rich forms leveraging the power of plugins and configurations in django_tomselect.

Visual Examples

Screenshot: Article List Screenshot: Article Update 1 Screenshot: Article Update 2


Key Code Segments

Forms

List Articles Filters

The filtering form utilizes TomSelectChoiceField for selecting year and word count ranges.

Create Article Form

The “Create Article” form employs TomSelectModelChoiceField and TomSelectModelMultipleChoiceField to manage relationships like authors, categories, and more.


Templates

List Articles

The filter form and article list are rendered in the template with built-in styling and dynamic updates.

Articles Form Template

The form is displayed using Bootstrap styling and django_tomselect integrations. Here, we manually laid out the form, but you can use django-crispy-forms or other form libraries for more automation.


Autocomplete Views

Multiple autocomplete views are used to populate the dropdowns with dynamic data, such as categories, authors, and article statuses. Please see the example app’s Autocomplete Views Code for more details.


Views

List Articles

Dynamic filters retrieve data using autocomplete endpoints.

Create / Update Article

The form is rendered with dynamic fields based on the article instance.


Design and Implementation Notes

Key Features

  • Dynamic Filtering: Use django_tomselect for real-time filtering in the article list.

  • Relationship Management: Leverage multi-select dropdowns for managing complex relationships like authors and categories.

Design Decisions

  • Using plugin_dropdown_header enhances the dropdown with contextual information (e.g., article count for authors).

  • plugin_dropdown_footer allows quick navigation to related views, like creating new magazines.