Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nnseva/django-taggit-bulk
Taggit package extension for bulk tagging instances from the model admin list view
https://github.com/nnseva/django-taggit-bulk
admin bulk-operation django django-admin taggit
Last synced: 3 months ago
JSON representation
Taggit package extension for bulk tagging instances from the model admin list view
- Host: GitHub
- URL: https://github.com/nnseva/django-taggit-bulk
- Owner: nnseva
- License: lgpl-3.0
- Created: 2020-05-15T17:55:00.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-21T11:28:11.000Z (almost 2 years ago)
- Last Synced: 2024-04-24T19:24:08.361Z (9 months ago)
- Topics: admin, bulk-operation, django, django-admin, taggit
- Language: Python
- Homepage:
- Size: 31.3 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Tests](https://github.com/nnseva/django-taggit-bulk/actions/workflows/test.yml/badge.svg)](https://github.com/nnseva/django-taggit-bulk/actions/workflows/test.yml)
# Django Taggit Bulk
The [Django Taggit Bulk](https://github.com/nnseva/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](https://django-taggit.readthedocs.io/en/latest/index.html) package.
## Installation
*Stable version* from the PyPi package repository
```bash
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:
```python
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'taggit_bulk',
...
]
```Include urlconf into the project root urlconf file, like:
```python
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`
```python
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:
```python
from django.contrib import admin
from django.contrib.admin import ModelAdminfrom .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](https://django-taggit.readthedocs.io/en/latest/index.html) package.
## Customization
### settings.py
You can setup `TAGGIT_BULK_SETTINGS` attribute of the settings.py file in your project.
```python
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:```python
from django.contrib import admin
from django.contrib.admin import ModelAdminfrom .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'`