Skip to content

This repository is desired to be a better implementation of Django's admin search

License

Notifications You must be signed in to change notification settings

eka-care/django-better-search

Repository files navigation

django-better-search

Downloads Downloads Downloads

PyPI version

This repo is heavily influenced by django-admin-search and copies some of the components as well.

This repo implements search on Django admin page differently. It generates different search boxes for separate fields and doesn't treat all of those fields as string.

Requirements

This app is tested using following:

  • Django >= 3.2
  • Python >= 3.9

Installation

This repo is published on Pypi. You can install it from there using following:

pip install django-better-search

Usage

  1. Add django_separate_search in your INSTALLED_APPS. Example:
INSTALLED_APPS = [
    ...
    "django_separate_search",
    ...
]
  1. Create a search form to have search fields on your admin page. Example:
from django.forms import CharField, Form, IntegerField


class UserSearchForm(Form):
    name = CharField(required=False, label="User's Name", help_text="Some help_text")
    age = IntegerField(required=False, label="User's Age", help_text="Another help_text")
    ...
  1. Use the search form in your AppAdmin in your admin.py. Example:
from django_separate_search.admin import SeparateSearchAdmin


class UserAdmin(SeparateSearchAdmin):
    ...
    search_form = UserSearchForm
    ...

This will render your search-form fields on the list-view admin page.

  1. If you want to implement search on a custom field, you will have to implement search_<field_name>. Example:
class UserAdmin(SeparateSearchAdmin):
    ...

    def search_<field_name>(self, field, field_value, form_field, request, param_values):
        query = Q()
        // Implement your query

        return query

Images

This is how search will look in admin view-list: modal

About

This repository is desired to be a better implementation of Django's admin search

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published