A Django library that adds autocomplete functionality to the admin search bar
Project description
Django Admin Autocomplete
A Django package that adds autocomplete functionality to the Django admin search bar. It provides a seamless way to search through your models in the admin interface with real-time suggestions.
Features
- Real-time search suggestions in Django admin
- Keyboard navigation support (arrow keys, enter, escape)
- Customizable minimum characters for search
- Supports multiple search fields
- Modern and responsive design
- Easy integration with existing Django admin
Installation
pip install django-admin-autocomplete
Quick Start
- Add
admin_autocompleteto yourINSTALLED_APPS:
INSTALLED_APPS = [
'django.contrib.admin',
...
'admin_autocomplete',
]
- Use the
AutocompleteAdminMixinin your ModelAdmin:
from django.contrib import admin
from admin_autocomplete.admin import AutocompleteAdminMixin
from .models import YourModel
@admin.register(YourModel)
class YourModelAdmin(AutocompleteAdminMixin, admin.ModelAdmin):
search_fields = ['title', 'description'] # Fields to search
Configuration
You can customize the autocomplete behavior in your Django settings:
ADMIN_AUTOCOMPLETE = {
'MIN_CHARS': 2, # Minimum characters before showing suggestions
'MAX_RESULTS': 10, # Maximum number of suggestions to show
}
Example
Here's a complete example using a Book model:
# models.py
from django.db import models
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=100)
description = models.TextField()
published_date = models.DateField()
isbn = models.CharField(max_length=13)
def __str__(self):
return f"{self.title} by {self.author}"
# admin.py
from django.contrib import admin
from admin_autocomplete.admin import AutocompleteAdminMixin
from .models import Book
@admin.register(Book)
class BookAdmin(AutocompleteAdminMixin, admin.ModelAdmin):
search_fields = ['title', 'author', 'isbn']
Running Tests
The package includes comprehensive tests, including end-to-end tests using Selenium. To run the tests:
# Install test dependencies
pip install -e ".[dev]"
# Run tests
python manage.py test admin_autocomplete.tests
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_autocomplete-0.1.1.tar.gz.
File metadata
- Download URL: django_admin_autocomplete-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fdfb24801d0725e8b7f666d367e1bed66c880da7a156870c5d446f3af45f998
|
|
| MD5 |
25fc13d1a4990050cb5202a3176b57a7
|
|
| BLAKE2b-256 |
72dd6122ca4129743e7bd396cc13ebe8a0f399656e3bf73282caba77e07c81e4
|
File details
Details for the file django_admin_autocomplete-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_admin_autocomplete-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c954c43824d746c944f0c14ad1c0cebf697ee2efb82dacb0bbd914ef37816131
|
|
| MD5 |
8fc2cd8e5ed1f1f1ed34b5fe6e6452fa
|
|
| BLAKE2b-256 |
918b5106942f6f93ff379aebe2adfe754996eb19371e7d895a851df597ac241a
|