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.0.tar.gz (11.4 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.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_admin_autocomplete-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d347ab8f4e41bc321d374a1dde77a4d0a24810949bae0b275c9b8b2283c2836b
MD5 46c24206a88ea14a900d4fa0d98279a3
BLAKE2b-256 e027493fd4da4ff03ee1b5309be23858d5658ea2bb5c5853acec2168f606af42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_admin_autocomplete-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a992c3f5553e6566bc0f17fe275e831328cd9e4b81c4ad0007277a6927fa927
MD5 ce603c100f88820f6a7ed85313e8f709
BLAKE2b-256 54a711a5a33c08c0080ac3673ab580210c3a15c542b42d48a2801b9bb29abd11

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