All Projects → demiroren-teknoloji → django-admin-autocomplete-list-filter

demiroren-teknoloji / django-admin-autocomplete-list-filter

Licence: MIT license
Ajax autocomplete list filter for Django admin

Programming Languages

python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to django-admin-autocomplete-list-filter

Django Flat Responsive
📱 An extension for Django admin that makes interface mobile-friendly. Merged into Django 2.0
Stars: ✭ 249 (+266.18%)
Mutual labels:  django-admin
django-sqlalchemy
Django ORM built on top of SQLalchemy core 2.0 for seamless integration of SQLAlchemy with Django 4.1+ PostgreSQL 14+ only for now. [pre POC now]
Stars: ✭ 101 (+48.53%)
Mutual labels:  django-admin
PyShop
PyShop is an online Python Ecommerce website built with Django, SQLite and Bootstrap. A simple and lightweight ecommerce app easily deployable anywhere anytime with modules developed upon the inbuilt django admin.
Stars: ✭ 17 (-75%)
Mutual labels:  django-admin
django-admin-extra-urls
Single mixin class to easily add buttons on any Django ModelAdmin related page
Stars: ✭ 26 (-61.76%)
Mutual labels:  django-admin
django-haystackbrowser
View and debug the data in your Haystack search indexes, from within the Django admin.
Stars: ✭ 36 (-47.06%)
Mutual labels:  django-admin
django-yaaac
Ajax Autocomplete Django application
Stars: ✭ 13 (-80.88%)
Mutual labels:  django-admin
Django Admin Env Notice
Visually distinguish environments in Django Admin
Stars: ✭ 207 (+204.41%)
Mutual labels:  django-admin
django admin chart js
An example repo showing how to add Chart.js to Django admin
Stars: ✭ 35 (-48.53%)
Mutual labels:  django-admin
django-export-action
Generic export action for Django's Admin
Stars: ✭ 47 (-30.88%)
Mutual labels:  django-admin
django-quill
Easily use Quill.js in your django admin.
Stars: ✭ 54 (-20.59%)
Mutual labels:  django-admin
django-admin-search
Modal filter for django admin
Stars: ✭ 60 (-11.76%)
Mutual labels:  django-admin
django-clone
Controlled Django model instance replication.
Stars: ✭ 89 (+30.88%)
Mutual labels:  django-admin
django-admin-shell
Django/Python shell for django admin site.
Stars: ✭ 62 (-8.82%)
Mutual labels:  django-admin
Django Practice Book
《Django企业开发实战》已出版
Stars: ✭ 251 (+269.12%)
Mutual labels:  django-admin
django-admin-charts
Create beautiful configurable charts from your models and display them on the django-admin index page or on django-admin-tools dashboard. The charts are based on models and criterias defined through admin interface and some chart parameters are configurable in live view.
Stars: ✭ 78 (+14.71%)
Mutual labels:  django-admin
Django Admin List Filter Dropdown
Use dropdowns in Django admin list filter
Stars: ✭ 215 (+216.18%)
Mutual labels:  django-admin
django-code-generator
Generate code from your Django models for faster development
Stars: ✭ 35 (-48.53%)
Mutual labels:  django-admin
django-lock-tokens
A Django application that provides a locking mechanism to prevent concurrency editing.
Stars: ✭ 19 (-72.06%)
Mutual labels:  django-admin
django-admin-confirm
AdminConfirmMixin is a mixin for ModelAdmin that adds confirmations to changes, additions and actions.
Stars: ✭ 34 (-50%)
Mutual labels:  django-admin
django-learning-pathway
(Currently in development) Learning pathways for learning Django.
Stars: ✭ 35 (-48.53%)
Mutual labels:  django-admin

Python Python Python Python Django Code style: black PyPI version Downloads

django-admin-autocomplete-list-filter

Ajax autocomplete list filter helper for Django admin. Uses Django’s built-in autocomplete widget! No extra package or install required!

After

Update

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

Installation and Usage

$ 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']

Development

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!

License

This project is licensed under MIT


Contributor(s)


Contribute

All PR’s are welcome!

  1. fork (https://github.com/demiroren-teknoloji/django-admin-autocomplete-list-filter/fork)
  2. Create your branch (git checkout -b my-features)
  3. commit yours (git commit -am 'added killer options')
  4. push your branch (git push origin my-features)
  5. Than create a new Pull Request!

TODO

  • Add unit tests
  • Improve JavaScript code :)

Change Log

2021-08-17

2019-10-25

  • Remove f-string for older Python versions, will change this on 1.0.0 version

2019-10-19

  • Bump version: 0.1.2
  • Add Python 3.5 supports, thanks to Peter Farrel
  • Add animated gif :)
  • Add future warning for f-strings

2019-10-11

  • Add ManyToManyField support
  • Initial release

2019-10-07

  • Init repo...
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].