Giter Club home page Giter Club logo

django-search-admin-autocomplete's Introduction

Django-search-admin-autocomplete

Simple django app that add autocomplete to search inside admin panel.

https://raw.githubusercontent.com/linevych/django-search-admin-autocomplete/master/doc/demo.gif

Requirements

  • Python: 3.5+
  • Django: >=1.11

Installation

pip install django-search-admin-autocomplete
# OR
pip install git+https://github.com/linevych/django-search-admin-autocomplete.git
INSTALLED_APPS = [
...
'search_admin_autocomplete',
...
]

Usage

from search_admin_autocomplete.admin import SearchAutoCompleteAdmin

class MyModelAdmin(SearchAutoCompleteAdmin)
    search_fields = ['search_field', ]

admin.site.register(MyModel, MyModelAdmin)

Customization

If admin/change_list.html is customized

admin.py

from search_admin_autocomplete.admin import SearchAutoCompleteAdmin

class MyModelAdmin(SearchAutoCompleteAdmin)

    change_list_template = 'admin/custom-list.html'

    search_fields = ['search_field', ]

admin.site.register(MyModel, MyModelAdmin)

admin/custom-list.html

{% extends 'search_admin_autocomplete/change_list.html' %}

{% block object-tools %}
Your custom html...
{{ block.super }}
{% endblock %}

MyPy

This project supports MyPy but to run type checks you need Python 3.6+.

pip install -r requirements_dev.txt
PYTHONPATH="$PYTHONPATH:$PWD/example" mypy search_admin_autocomplete

django-search-admin-autocomplete's People

Contributors

alfa24 avatar denkneb avatar haideralipunjabi avatar linevych avatar nautatva avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-search-admin-autocomplete's Issues

The autocomplete does not work

I have tried your code example but the autocomplete does not work.

from search_admin_autocomplete.admin import SearchAutoCompleteAdmin

class ImportBuildingUnitAdmin(SearchAutoCompleteAdmin, ImportExportModelAdmin):
    list_display = ( 'bu__short_name',)
    search_fields = ['bu__short_name', ]

I have included search_admin_autocomplete change list template also.

Please rectify the issue. Thank you.

Django 2.2.4
Python 3.7

multiple fields

it doesn't work with the multiple search fields?
if multiple fileds, it could't autocomplete.

Using JavaScript to reduce requests to server

In many cases, the requests going to the server becomes very high. Using client-side JavaScript for web pages, we can reduce these requests bearing the risk for outdated data. Perhaps can make a switch to decide between client-side searches vs server-side searches.

Refactor as Mixin

Just a small suggestion.

Maybe you could refactor your admin class to be used as a Mixin rather than as BaseClass.
Like DjangoQl does.
So instead of writing

class MyModelAdmin(SearchAutoCompleteAdmin)
    search_fields = ['search_field', ]

you'd write

class MyModelAdmin(SearchAutoCompleteMixin, admin.ModelAdmin)
    search_fields = ['search_field', ]

That way your functionality could probably also be used when using other admin extensions (e.g. [django-nested-admin])(https://pypi.org/project/django-nested-admin/).

I know, multiple inheritance is a controversial topic. But in Django its used all the time (see class based views) so why not use it here?

Correct me, if I'm wrong, but I think the only thing needed for this would be to simply drop the inheritance from this line
from class SearchAutoCompleteAdmin(admin.ModelAdmin): to class SearchAutoCompleteAdmin:.
And maybe a custom error message on this classes __init__ if it gets used without importing admin.

Tell me, what you think :)

Django4 compat

From django 4.x - url in django .confs is no longer available.

Fix:

  1. replace import by

    from django.urls import include, re_path

  2. replace url() on line 34 with

    re_path( ....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.