django-search-input-field


Namedjango-search-input-field JSON
Version 0.1.15 PyPI version JSON
download
home_pagehttps://github.com/MinaAtef1/django-search-input-form
SummaryA Django app providing a search input field.
upload_time2024-08-14 13:09:38
maintainerNone
docs_urlNone
authorMina Atef
requires_python>=3.6
licenseMIT
keywords django search input field
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django Search Input Field

The Django Search Input Field package simplifies the process of integrating Ajax searchable input fields into Django forms. This package provides flexibility for searching model fields or any custom data, enhancing the user experience and improving search functionality within your Django applications.

![Django Search Field](https://github.com/minaaaatef/django-search-input-form/assets/36309814/3de1774b-4981-4717-a093-734ea55ba5ff)

## Installation

You can install the package via pip:

```shell
pip install django-search-input-field
```

Once installed, add the app to your `INSTALLED_APPS` in your Django settings:

```python
INSTALLED_APPS = [
    ...
    "django_search_input_field"
]
```

Finally, include the package's URLs in your project's URL configuration:

```python
urlpatterns = [
    path('django_search_input_field/', include('django_search_input_field.urls')),
]
```

## Usage

### Field Types

#### SelectSearchCharField

The `SelectSearchCharField` is used to perform a search on a specified field and return the field value.

Example Usage:

```python
from django import forms
from django_search_input_field.field import SelectSearchCharField
from Main.models import Customers
from rest_framework.permissions import AllowAny

class CustomerSearchFieldForm(forms.Form):
    name = SelectSearchCharField(field="name", model=Customers, permissions=AllowAny)
```
#### SearchModelField
The SearchModelField is used to search based on a specified field but returns the entire model object, using the field for searching.

Example Usage:
```python 
from django import forms
from django_search_input_field.field import SearchModelField
from Main.models import Customers
from rest_framework.permissions import AllowAny

class CustomerSearchFieldForm(forms.Form):
    name = SearchModelField(model=Customers, search_field="name", permissions=AllowAny)
```

#### Related Form and CharRelatedField 
The related form is used to fill related fields automatically when a SearchModelField is selected.

Example Usage:
```python
from django_search_input_field.field import CharRelatedField, SearchModelField
from django_search_input_field.form import RelatedFillForm

from Main.models import Customers
from rest_framework.permissions import AllowAny

class CustomerSearchFieldWithRelatedForm(RelatedFillForm):
    name = SearchModelField(model=Customers, search_field="name", permissions=AllowAny)
    email = CharRelatedField(related_field="name", related_search_input="email")
```


## Advanced Usage
The package provides the flexibility to customize the search behavior by creating custom providers.
you can provide the provider name to the field using query_function_name parameter.

### Custom Providers
You can create custom providers to tailor the search behavior according to your specific requirements.

Here's an example of creating a custom provider:


```python
from django_search_input_field.providers import SearchModelProvider

class CustomModelProvider(SearchModelProvider):
    model = YourModel
    query_function_name = 'custom_search_function'
    auto_register = False

    def get_queryset(self):
        # Implement your custom queryset logic here
        return YourModel.objects.all()

    def get_filtered_queryset(self, function_filters, search_key):
        # Implement your custom filtered queryset logic here
        return YourModel.objects.filter(**function_filters)

    def get_filtered_options(self, function_filters, search_key):
        options = self.get_filtered_queryset(function_filters, search_key)
        return [ModelOption(option, serializer=None, object_str=lambda obj: str(obj)) for option in options]
```

### Using Custom Providers
After creating a custom provider, you can use it in your form or field:

```python
from django import forms
from django_search_input_field.field import SearchModelField
from .providers import CustomModelProvider

class YourForm(forms.Form):
    custom_field = SearchModelField(
        model=None,
        search_field="your_field",
        permissions=YourCustomPermissionsClass,
        query_function_name=CustomModelProvider.query_function_name,
        min_search_length=1,
    )
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MinaAtef1/django-search-input-form",
    "name": "django-search-input-field",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "django search input field",
    "author": "Mina Atef",
    "author_email": "mina.atef0@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ae/ba/e509178a7332b8bbf740f186ab0bc578d72d13becf09f454e651fac66bc2/django-search-input-field-0.1.15.tar.gz",
    "platform": null,
    "description": "# Django Search Input Field\n\nThe Django Search Input Field package simplifies the process of integrating Ajax searchable input fields into Django forms. This package provides flexibility for searching model fields or any custom data, enhancing the user experience and improving search functionality within your Django applications.\n\n![Django Search Field](https://github.com/minaaaatef/django-search-input-form/assets/36309814/3de1774b-4981-4717-a093-734ea55ba5ff)\n\n## Installation\n\nYou can install the package via pip:\n\n```shell\npip install django-search-input-field\n```\n\nOnce installed, add the app to your `INSTALLED_APPS` in your Django settings:\n\n```python\nINSTALLED_APPS = [\n    ...\n    \"django_search_input_field\"\n]\n```\n\nFinally, include the package's URLs in your project's URL configuration:\n\n```python\nurlpatterns = [\n    path('django_search_input_field/', include('django_search_input_field.urls')),\n]\n```\n\n## Usage\n\n### Field Types\n\n#### SelectSearchCharField\n\nThe `SelectSearchCharField` is used to perform a search on a specified field and return the field value.\n\nExample Usage:\n\n```python\nfrom django import forms\nfrom django_search_input_field.field import SelectSearchCharField\nfrom Main.models import Customers\nfrom rest_framework.permissions import AllowAny\n\nclass CustomerSearchFieldForm(forms.Form):\n    name = SelectSearchCharField(field=\"name\", model=Customers, permissions=AllowAny)\n```\n#### SearchModelField\nThe SearchModelField is used to search based on a specified field but returns the entire model object, using the field for searching.\n\nExample Usage:\n```python \nfrom django import forms\nfrom django_search_input_field.field import SearchModelField\nfrom Main.models import Customers\nfrom rest_framework.permissions import AllowAny\n\nclass CustomerSearchFieldForm(forms.Form):\n    name = SearchModelField(model=Customers, search_field=\"name\", permissions=AllowAny)\n```\n\n#### Related Form and CharRelatedField \nThe related form is used to fill related fields automatically when a SearchModelField is selected.\n\nExample Usage:\n```python\nfrom django_search_input_field.field import CharRelatedField, SearchModelField\nfrom django_search_input_field.form import RelatedFillForm\n\nfrom Main.models import Customers\nfrom rest_framework.permissions import AllowAny\n\nclass CustomerSearchFieldWithRelatedForm(RelatedFillForm):\n    name = SearchModelField(model=Customers, search_field=\"name\", permissions=AllowAny)\n    email = CharRelatedField(related_field=\"name\", related_search_input=\"email\")\n```\n\n\n## Advanced Usage\nThe package provides the flexibility to customize the search behavior by creating custom providers.\nyou can provide the provider name to the field using query_function_name parameter.\n\n### Custom Providers\nYou can create custom providers to tailor the search behavior according to your specific requirements.\n\nHere's an example of creating a custom provider:\n\n\n```python\nfrom django_search_input_field.providers import SearchModelProvider\n\nclass CustomModelProvider(SearchModelProvider):\n    model = YourModel\n    query_function_name = 'custom_search_function'\n    auto_register = False\n\n    def get_queryset(self):\n        # Implement your custom queryset logic here\n        return YourModel.objects.all()\n\n    def get_filtered_queryset(self, function_filters, search_key):\n        # Implement your custom filtered queryset logic here\n        return YourModel.objects.filter(**function_filters)\n\n    def get_filtered_options(self, function_filters, search_key):\n        options = self.get_filtered_queryset(function_filters, search_key)\n        return [ModelOption(option, serializer=None, object_str=lambda obj: str(obj)) for option in options]\n```\n\n### Using Custom Providers\nAfter creating a custom provider, you can use it in your form or field:\n\n```python\nfrom django import forms\nfrom django_search_input_field.field import SearchModelField\nfrom .providers import CustomModelProvider\n\nclass YourForm(forms.Form):\n    custom_field = SearchModelField(\n        model=None,\n        search_field=\"your_field\",\n        permissions=YourCustomPermissionsClass,\n        query_function_name=CustomModelProvider.query_function_name,\n        min_search_length=1,\n    )\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Django app providing a search input field.",
    "version": "0.1.15",
    "project_urls": {
        "Homepage": "https://github.com/MinaAtef1/django-search-input-form"
    },
    "split_keywords": [
        "django",
        "search",
        "input",
        "field"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aebae509178a7332b8bbf740f186ab0bc578d72d13becf09f454e651fac66bc2",
                "md5": "007da769508b8c0582d648cd571b0609",
                "sha256": "71d3e12516c2982318e6bf269df4c55e81db1a10c0dac466068fe4418f6283a0"
            },
            "downloads": -1,
            "filename": "django-search-input-field-0.1.15.tar.gz",
            "has_sig": false,
            "md5_digest": "007da769508b8c0582d648cd571b0609",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11088,
            "upload_time": "2024-08-14T13:09:38",
            "upload_time_iso_8601": "2024-08-14T13:09:38.969090Z",
            "url": "https://files.pythonhosted.org/packages/ae/ba/e509178a7332b8bbf740f186ab0bc578d72d13becf09f454e651fac66bc2/django-search-input-field-0.1.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-14 13:09:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MinaAtef1",
    "github_project": "django-search-input-form",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-search-input-field"
}
        
Elapsed time: 0.36555s