Skip to main content

A different implementation of Django's admin search

Project description

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

Note: This project is not yet ready for production use.

  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

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_better_search-0.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

django_better_search-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file django_better_search-0.2.0.tar.gz.

File metadata

  • Download URL: django_better_search-0.2.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for django_better_search-0.2.0.tar.gz
Algorithm Hash digest
SHA256 aeee2015a4a7222205677db96921ba077f0946d66b05bf8b8253d166c7b83168
MD5 b25d4a1af2283470e1cde03c015f12f0
BLAKE2b-256 cd54d565663fcafa2264fdea19839e8dca2c9d19e1f07ee12432b1faa311b724

See more details on using hashes here.

File details

Details for the file django_better_search-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_better_search-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 401078f00bd358709e0c4415e4b5f3e561f089501e63cd348a3de79623179933
MD5 2b733d60b673a2cebf08d82403ce8d52
BLAKE2b-256 9d00daa1f06d3d8ac1d46ed49970fdd18a48fc3aa60603637fd609dfff82c1ec

See more details on using hashes here.

Supported by

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