Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 2.14 KB

charfield.rst

File metadata and controls

65 lines (46 loc) · 2.14 KB

CharField autocompletes

django-tagging and derivates like django-tagging-ng provide a TagField, which is a CharField expecting comma separated tags. Behind the scenes, this field is parsed and Tag model instances are created and/or linked.

A stripped variant of widget.js, text_widget.js, enables autocompletion for such a field. To make it even easier, a stripped variant of Widget, TextWidget, automates configuration of text_widget.js.

Needless to say, TextWidget and text_widget.js have a structure that is consistent with Widget and widget.js.

It doesn't have many features for now, but feel free to participate to the project on GitHub.

As usual, a working example lives in test_project. in app charfield_autocomplete.

Warning

Note that this feature was added in version 1.0.16, if you have overloaded autocomplete_light/static.html from a previous version then you should make it load autocomplete_light/text_widget.js to get this new feature.

Example

This demonstrates a working usage of TextWidget:

../../autocomplete_light/example_apps/charfield_autocomplete/forms.py

FTR, using the form in the admin is still as easy:

../../autocomplete_light/example_apps/charfield_autocomplete/admin.py

So is registering an Autocomplete for Tag:

../../autocomplete_light/example_apps/charfield_autocomplete/autocomplete_light_registry.py

Django-tagging

This demonstrates the models setup used for the above example, using django-taggit, which provides a normal CharField behaviour:

../../autocomplete_light/example_apps/charfield_autocomplete/models.py

Django-taggit

For django-taggit, you need autocomplete_light.contrib.taggit_tagfield <contrib>.