Skip to content

Conversation

@mrjoshuap
Copy link
Contributor

Description

This PR fixes a critical bug where tags and categories added to media items were not immediately searchable, and improves the user experience by sorting tags and categories alphabetically throughout the frontend.

Bug Fix: Immediate Search Vector Updates for Tags and Categories

Previously, when tags or categories were added to media items via M2M relationships, the search vectors were not updated until the media item was edited a second time. This meant that newly tagged media would not appear in search results until manually re-saved.

Changes:

  • Added M2M signal handlers (m2m_changed) for Media.tags and Media.category relationships that automatically update search vectors and tag/category media counts when relationships change
  • Signal handlers properly handle post_add, post_remove, and post_clear actions using the pk_set parameter to identify affected tags/categories
  • Added explicit search vector updates in bulk tag/category operations (MediaBulkUserActions) to ensure consistency
  • Added search vector update in edit_media view to ensure changes are immediately reflected

Fixes: #1207

Enhancement: Alphabetical Sorting of Tags and Categories

To improve usability and make tags/categories easier to find and scan, all tag and category lists are now sorted alphabetically (case-insensitive).

Changes:

  • Updated Media.tags_info and Media.categories_info properties to return sorted lists alphabetically by title
  • Updated BulkActionTagModal component to sort tags alphabetically in both left (available tags) and right (selected tags) panels

Steps

Pre-deploy

  • No special pre-deployment steps required
  • The signal handlers will automatically activate once deployed

Post-deploy

  • No database migrations required
  • Existing media items with tags/categories will have their search vectors updated automatically on the next edit or when tags/categories are modified
  • Consider running a management command to refresh search vectors for all media items if immediate searchability is critical (optional):
    from files.models import Media
    for media in Media.objects.all():
        media.update_search_vector()

mrjoshuap and others added 4 commits December 23, 2025 13:05
…ips change

- Add M2M signal handlers for Media.tags and Media.category that update
  search vectors and tag/category media counts immediately
- Use pk_set parameter to properly update counts for removed tags/categories
- Add explicit search vector updates in edit_media view and bulk actions
- Fixes issue where tags added to media weren't searchable until second edit

Fixes mediacms-io#1207
- Sort tags_info and categories_info properties alphabetically by title
  (case-insensitive) in Media model
- Sort tags alphabetically in BulkActionTagModal left and right panels
- Improves usability by making tags easier to find and scan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant