Skip to main content

Django jQuery Tags Input is a Django field and widget wrapper that adds an easy to use interface for `ManyToManyField` and `ForeignKey` fields in the forms of autocompleting tags with optionally live creation of new linked items

Project description

Overview

https://travis-ci.org/WoLpH/django-tags-input.svg?branch=master https://coveralls.io/repos/WoLpH/django-tags-input/badge.svg?branch=master

Django Tags Input is a module that gives you a modified version of the Xoxco jQuery Tags Input library within Django.

The result is a very pretty interface with tags and autocomplete which can optionally automatically create new items when they are missing.

One of the most useful features of Django Tags Input is that it stores the elements in the order which you input.

So if you insert B, A, C into the database, it will return it sorted the way you entered it: B, A, C.

https://raw.githubusercontent.com/WoLpH/django-tags-input/master/docs/example.png

How to install

Installing this module only takes a couple of minutes.

Currently Django 2.2, 3.1 and 3.2 are supported and tested in combination with Python 3.7, 3.8, 3.9 and 3.10.

For Django below 2.2 and Python 2.7 up to version 4.6.0 should work.

For Django 1.4, Django 1.5, Django 1.6 and Django 1.7 in combination with Python 2.6 and 2.7. Python 3.2, 3.3 and 3.4. Pypy and Pypy3 version 2.1.0 can be used.

  1. Install the module itself

    pip install django-tags-input

    # or

    easy_install django-tags-input

  2. Add tags_input to your INSTALLED_APPS setting in the Django settings.py.

    Example:

    INSTALLED_APPS = (
        # ... your other installed apps
        'tags_input',
    )
  3. Add the mappings to your settings.py file:

    Example:

    TAGS_INPUT_MAPPINGS = {
        'some_app.SomeKeyword': {
            'field': 'some_field',
        },
        'some_app.SomeOtherKeyword': {
            'fields': ('some_field', 'some_other_field'),
        },
        'some_app.SomeSortedKeyword': {
            'field': 'some_field',
            'ordering': [
                'some_field',
                'some_other_field',
            ],
            'filters': {
                'some_field__istartswith': 'a',
            },
            'excludes': {
                'some_field__iexact': 'foobar',
            },
        },
        'some_app.SomeCreateableKeyword': {
            'field': 'some_field',
            'create_missing': True,
        },
    }
  4. Add the tags_input urls to your urls.py:

    Example:

    from django.conf import urls
    
    urlpatterns = patterns('',
        url(r'^tags_input/', include('tags_input.urls', namespace='tags_input')),
        # ... other urls ...
    )

Admin usage

from django.contrib import admin
import models
from tags_input import admin as tags_input_admin

class YourAdmin(tags_input_admin.TagsInputAdmin):

    #Optionally specify which ManyToMany fields are to be used for tagging
    #Or define a get_tag_fields() method
    tag_fields = ["some_field"]

admin.site.register(models.YourModel, YourAdmin)

Quickstart

To test the project simply clone the repository, install and run the example:

# mkvirtualenv is part of virtualenvwrapper, using a regular virtualenv, pyvenv or pipenv is also possible
# Or even without any type of virtualenv at all
mkvirtualenv django-tags-input
git clone https://github.com/WoLpH/django-tags-input.git
# Tested with Django 3.0
pip install django
pip install -e 'django-tags-input[tests]'
cd django-tags-input/example
python manage.py runserver

Now you can go to http://localhost:8000/admin/ and login with username and password admin and admin respectively.

After this you can try adding some extra Foo objects through the Spam admin here: http://localhost:8000/admin/autocompletionexample/spam/2/

Note that some parts of the example are deliberately broken to test the behaviour in broken environments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tags-input-5.1.0.tar.gz (117.1 kB view details)

Uploaded Source

Built Distribution

django_tags_input-5.1.0-py2.py3-none-any.whl (119.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-tags-input-5.1.0.tar.gz.

File metadata

  • Download URL: django-tags-input-5.1.0.tar.gz
  • Upload date:
  • Size: 117.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.8

File hashes

Hashes for django-tags-input-5.1.0.tar.gz
Algorithm Hash digest
SHA256 eda0de4594a5674d3b8aeaca1240bc3a9132e441c10ede79c6f113f8e49242aa
MD5 4badf449c72e38b07412aa50725634c6
BLAKE2b-256 d835d368f49c6436736690a31359184ffb5fdc0bcdf7dcf474e8062a681a5834

See more details on using hashes here.

File details

Details for the file django_tags_input-5.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_tags_input-5.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b0a879da69737f4586e7b0cea218e8617ace0b235d1847d5fb9ab94a37d65584
MD5 c0c5d79390a34ecec9b6b8e102a88934
BLAKE2b-256 b6bd1ab35ac63c5c6f1ce0638acfc8c5777d7a2bd8c6a4d68635626ed1c8739e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page