Skip to main content

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

  1. Add admin_autocomplete to your INSTALLED_APPS:
INSTALLED_APPS = [
    'django.contrib.admin',
    ...
    'admin_autocomplete',
]
  1. Use the AutocompleteAdminMixin in 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_admin_autocomplete-0.1.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_admin_autocomplete-0.1.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_autocomplete-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django_admin_autocomplete-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6fdfb24801d0725e8b7f666d367e1bed66c880da7a156870c5d446f3af45f998
MD5 25fc13d1a4990050cb5202a3176b57a7
BLAKE2b-256 72dd6122ca4129743e7bd396cc13ebe8a0f399656e3bf73282caba77e07c81e4

See more details on using hashes here.

File details

Details for the file django_admin_autocomplete-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_autocomplete-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c954c43824d746c944f0c14ad1c0cebf697ee2efb82dacb0bbd914ef37816131
MD5 8fc2cd8e5ed1f1f1ed34b5fe6e6452fa
BLAKE2b-256 918b5106942f6f93ff379aebe2adfe754996eb19371e7d895a851df597ac241a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page