mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
Select2 submits raw text as the value for new tags typed into the tag
box (tags: true + createTag in link_form.html). The previous
ModelMultipleChoiceField silently dropped those values because they
were not PKs of existing tags, so new tags were never persisted.
Add TagInputField, a tolerant ModelMultipleChoiceField subclass:
- existing tag PKs resolve as before
- raw text is treated as a new (or case-insensitive-existing) tag
- names are stripped and lowercased before get_or_create so the tag
namespace stays consistent and case-insensitive duplicates are
avoided. The Tag.save() hook still derives the slug.
LinkForm now uses TagInputField for its tags field, so both
LinkCreateView and LinkUpdateView pick up the new behaviour. The
Select2 createTag callback in link_form.html now lowercases the term
so users see immediately what will be stored.
Add 7 regression tests in TestLinkTagAutoCreate covering: new tag
created + lowercased; multiple new tags; existing tag reused (no
duplicate); mixed PK + new-text submission; no tags submitted; empty
or whitespace-only submission ignored; whitespace stripped.