Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
django-admin-autocomplete-list-filter
Advanced tools
Ajax autocomplete list filter helper for Django admin. Uses Django’s built-in autocomplete widget! No extra package or install required!
Dropped support for Django 2 family. Works with Django 3 or higher!. master
branch is renamed to main
... You can fix your existing clones via;
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
$ pip install django-admin-autocomplete-list-filter
Add djaa_list_filter
to INSTALLED_APPS
in your settings.py
:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djaa_list_filter',
]
Now, let’s look at this example model:
# models.py
from django.conf import settings
from django.db import models
class Post(models.Model):
category = models.ForeignKey(to='Category', on_delete=models.CASCADE, related_name='posts')
author = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='posts')
title = models.CharField(max_length=255)
body = models.TextField()
tags = models.ManyToManyField(to='Tag', blank=True)
def __str__(self):
return self.title
class Category(models.Model):
title = models.CharField(max_length=255)
def __str__(self):
return self.title
class Tag(models.Model):
name = models.CharField(max_length=255)
def __str__(self):
return self.name
We have 2 ForeignKey fields and one ManyToManyField to enable
autocomplete list filter feature on admin. All you need is to inherit from
AjaxAutocompleteListFilterModelAdmin
which inherits from Django’s
admin.ModelAdmin
.
Now we have an extra ModelAdmin method: autocomplete_list_filter
. Uses
Django Admin’s search_fields
logic. You need to enable search_fields
in the related ModelAdmin. To enable completion on Category
relation,
CategoryAdmin
should have search_fields
that’s it!
from django.contrib import admin
from djaa_list_filter.admin import (
AjaxAutocompleteListFilterModelAdmin,
)
from .models import Category, Post, Tag
@admin.register(Post)
class PostAdmin(AjaxAutocompleteListFilterModelAdmin):
list_display = ('__str__', 'author', 'show_tags')
autocomplete_list_filter = ('category', 'author', 'tags')
def show_tags(self, obj):
return ' , '.join(obj.tags.values_list('name', flat=True))
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
search_fields = ['title']
ordering = ['title']
@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
search_fields = ['name']
ordering = ['name']
You are very welcome to contribute, fix bugs or improve this project. We hope to help people who needs this feature. We made this package for our company project. Good appetite for all the Django developers out there!
This project is licensed under MIT
All PR’s are welcome!
fork
(https://github.com/demiroren-teknoloji/django-admin-autocomplete-list-filter/fork)branch
(git checkout -b my-features
)commit
yours (git commit -am 'added killer options'
)push
your branch
(git push origin my-features
)2021-08-17
master
branch is renamed to main
2019-10-25
2019-10-19
2019-10-11
2019-10-07
FAQs
Ajax autocomplete list filter for Django admin
We found that django-admin-autocomplete-list-filter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.