Git Product home page Git Product logo

django-admin-search's Introduction

Django Admin Search

Downloads Downloads Downloads

Coverage Quality Gate Status PyPI version
The "Django Admin Search" is a advanced search modal for django admin.

If you use or like the project, click Star and Watch to generate metrics and i evaluate project continuity.

Install:

pip install django-admin-search

Usage:

  1. Add to your INSTALLED_APPS, in settings.py:

    INSTALLED_APPS = [  
        ...
        'django_admin_search',
        ...
    ]
    
  2. Create a search form for model:

    from .models import Area
    from django.forms import ModelForm, Form
    from django.forms import DateField, CharField, ChoiceField, TextInput
    
    
    class YourFormSearch(Form):
        name = CharField(required=False)
        date = DateField(required=False, widget=TextInput(
            attrs={ 
                'filter_method': '__gte',
            }
        ))
    
  3. In your admin:

    from django_admin_search.admin import AdvancedSearchAdmin
    from .models import YourModel
    from .form import YourForm, YourFormSearch
    
    @register(YourModel)
    class YourAdmin(AdvancedSearchAdmin):
        form = YourForm
        search_form = YourFormSearch
    

Advanced:

  1. to multiple filters in same field:

    class YourFormSearch(Form):
        ...
        name = CharField(required=False)
        begin = DateField(required=False, widget=TextInput(
            attrs={
                'filter_field': 'date', 
                'filter_method': '__gte',
            }
        ))
        end = DateField(required=False, widget=TextInput(
            attrs={
                'filter_field': 'date', 
                'filter_method': '__lte',
            }
        ))
    
  2. add placeholder and mask

    class YourFormSearch(Form):
        ...
        date = DateField(required=False, widget=TextInput(
            attrs={
                'data-mask': "00/00/0000", 
                'placeholder': 'MM/DD/YYYY'
            }
        ))
    
  3. Custom filter query for a field

    from django_admin_search.admin import AdvancedSearchAdmin
    from .models import YourModel
    from .form import YourForm, YourFormSearch
    
    @register(YourModel)
    class YourAdmin(AdvancedSearchAdmin):
        def search_FieldNameHere(request, field_value, param_values):
            """
                intercept query filter for description field
            """
            query = Q()
            # your Q logic here
            return query
    

Images:

Button in admin list: input

Modal opened: modal

Development and Running the Tests

To do development work for Django Admin Search, clone it locally, make and activate a virtualenv for it, then from within the project directory:

pip install -e ".[dev]"

To run the tests:

pytest

If your work in high difficult test, and need to re run the test every time, use pytest-watch:

ptw  # this see file change and re run a test

when you need to see passed lines by test, run

pytest --cov-report html

after this, will be created a htmlcov folder in the root

To run sonar

pytest --cov-report xml
pylint ./django_admin_search/ --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" | tee pylint.txt
sonar-scanner

See your code quality in Sonar (in testing, no metrics to approve yet)

https://sonarcloud.io/dashboard?id=shinneider_django-admin-search

For future i want to run test's in Travis CI, to check if PR is Ok, but to be effective, i need to cover 80% or more of the code, help-me creating a test case, see this issue PR - 20

Need a Maintainer

In the last months i don't have much time, health problemas, change of country and others problems.
i have some surgeries for first part of 2022, and all of my current project don't use django-admin.
for these reasons, i need a help for a project continuation!!

django-admin-search's People

Contributors

abhi904485 avatar dependabot[bot] avatar franciscoda avatar gabbyprecious avatar shinneider avatar shinneider-ivory avatar yuriescl avatar

Watchers

 avatar

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.