Adding Tags Using Django-Taggit in Django Project
Django-Taggit is a Django application which is used to add tags to blogs, articles etc. It makes very easy for us to make adding the tags functionality to our django project.
Setting up Django Project
- Installing django-taggit
pip install django-taggit
- ADD it to Main Project’s settings.py file
- Changes To models.py file
Add TaggableManager in your post, blog, article modal
After adding TaggableManager run following commands in terminal
- python manage.py makemigrations
python manage.py migrate
The TaggableManager will show up automatically as a field in post modal
The Taggit Modal will also appear automatically as a separate modal in admin panel
1) If the tags input doesn’t contain any commas or double quotes, it will be taken as space-delimited list of
geeks for geeks => "geeks", "for", "geeks"
2) If the tags input does contain commas or double quotes then :
a) geeks, geeks for geeks => "geeks", "geeks for geeks" b) "geeks, forgeeks" geek geeksfor => "geeks, forgeeks", "geek", "geeksfor" c) "geeks, forgeeks", geek geeksfor => "geeks, forgeeks", "geeks geeksfor" d) geeks "for" geeks => "geeks", "for", "geeks"
After Adding Tags to the posts the taggit modal will look like :
On clicking the particular tag, There will come a list of all the posts associated with that particular tag. Now this model can be used with the project like other models