Git Product home page Git Product logo

django-taggit-bulk's Introduction

Tests

Django Taggit Bulk

The Django Taggit Bulk package provides an admin action to tag or untag selected instances from the model admin list page. It uses tagging system implemented by the Django Taggit package.

Installation

Stable version from the PyPi package repository

pip install django-taggit-bulk

Last development version from the GitHub source version control system

pip install git+git://github.com/nnseva/django-taggit-bulk.git

Configuration

Include the taggit_bulk application into the INSTALLED_APPS list, like:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    ...
    'taggit_bulk',
    ...
]

Include urlconf into the project root urlconf file, like:

urlpatterns = [
    ...
    url('^taggit/', include('taggit_bulk.urls')),
]

Install the tag_wizard action to list of actions for every admin class which controls model with installed TaggableManager.

For example, let's some your model has a TaggableManager installed:

models.py

class MyModel(models.Model):
    ...
    tags = TaggableManager(
        blank=True,
        verbose_name=_('Tags'), help_text=_('A comma-separated list of tags')
    )
    ...

Then your admin.py file should look like:

from django.contrib import admin
from django.contrib.admin import ModelAdmin

from .models import MyModel

from taggit_bulk.actions import tag_wizard


class MyModelAdmin(ModelAdmin):
    ...
    actions = [
        tag_wizard
    ]
    ...


admin.site.register(MyModel, MyModelAdmin)

That's it!

Usage

Select some number of instances in your model instance list view, choose an action "Bulk tag/untag selected objects" from the dropdown menu, and press the "Go" button.

You will see a simple dialog to setup tags for all of the selected instances.

You can either add, or remove tags for all instances, depending on the "Clear" flag in the dialog.

When deleting, if the tag is not found for a separate instance, nothing happens for this instance.

When adding, if the tag already present for a separate instance, nothing happens for this instance.

You can add or clear several tags together, just enlist them in a dialog separating by the comma.

The tags input string behaves exactly the same as for the Django Taggit package.

Customization

settings.py

You can setup TAGGIT_BULK_SETTINGS attribute of the settings.py file in your project.

TAGGIT_BULK_SETTINGS = {
    'session_prefix': 'tag_wizard_data',
}

The session_prefix key controls the session key where the data is stored for the dialog call.

Access restriction

You can restrict access to the objects to be changed by the wizard overloading a tag_wizard action.

Just use your own action function restricting QuerySet passed as a parameter, and call the original tag_wizard inside. For example:

from django.contrib import admin
from django.contrib.admin import ModelAdmin

from .models import MyModel

from taggit_bulk.actions import tag_wizard


class MyModelAdmin(ModelAdmin):
    ...
    actions = [
        "tag_wizard_restricted"
    ]
    def tag_wizard_restricted(self, request, queryset):
        queryset = queryset.filter(owner=request.user)
        return tag_wizard(self, request, queryset)
    tag_wizard_restricted.short_description = tag_wizard.short_description
    ...


admin.site.register(MyModel, MyModelAdmin)

Templating

You can overload the form template for the tag wizard.

Just install your own template named as one of the following:

  • 'taggit_bulk_wizard_form.html'
  • 'taggit_bulk/wizard_form.html'

You also can use the original name of the template found in the package installing it in any application following the taggit_bulk in the INSTALLED_APPS, or in the common project template directory:

  • 'taggit_bulk/wizard/form.html'

django-taggit-bulk's People

Contributors

nnseva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

django-taggit-bulk's Issues

django 4 'cannot import name url' from 'django.conf.urls'

I am using Django 4.0.6 and am trying to use the taggit_bulk package. Unfortunately when I go to import your urls.py I cannot use django.conf.urls.url as that was deprecated in 3 and removed for 4.0 of Django.

using re_path in my own urls allows me to import xxxx but when it gets to line 11 in taggit_bulk/urls.py there is an exception of:


  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\Projects\Python\dr_mercantile_exchange\venv\lib\site-packages\taggit_bulk\urls.py", line 4, in <module>
    from django.conf.urls import url
ImportError: cannot import name 'url' from 'django.conf.urls' (D:\Projects\Python\dr_mercantile_exchange\venv\lib\site-packages\django\conf\urls\__init__.py)

I tried to import your urls directly from my app but that lead to an even stranger url saying that taggit_bulk was not a registered namespace, which of course it was. I am fairly new to Django but I think all you need to do is change

from django.conf.urls import url
urlpatterns = [
url(r'^wizard/$', TaggitBulkWizard.as_view(), name='wizard'),
]

to

from django.urls import re_path
urlpatterns = [
re_path(r'^wizard/$', TaggitBulkWizard.as_view(), name='wizard'),
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.