Skip to main content

A package supplying tools for easy creating autocompletes with drf.

Project description

DRF complete autocomplete

Test package Coverage Status

Installation

$ pip install drf-complete-autocomplete
$ pip install drf-complete-autocomplete[django-filter]

How to use

Settings:

from drf_complete_autocomplete.configuration import AutocompleteModelDescription

from my_app.models import MyModel


AUTOCOMPLETE_MODELS = [
    AutocompleteModelDescription(
        api_name='my_model',
        model=MyModel,
        value_field='pk',
        label_field='__unicode__',
        icontains_search_fields=['name'],
        filterset=None,  # django-filter FilterSet
        order_by=['name'],
        distinct=False,
        results_limit=20,
    ),
]

Serializer:

...
from drf_autocomplete.serializers import WithAutocomplete
...


class SomeModelSerializer(WithAutocomplete, serializers.ModelSerializer):
    ...

    class Meta:
        model = SomeModel
        fields = [
            ...
            'related_to_my_model',
            ...
        ]
        ...
        autocomplete_fields = {
            'related_to_my_model': 'my_model',
        }

View:

You can import drf_complete_autocomplete.views.RetrieveAutocompleteResultsApiView and supply your AUTOCOMPLETE_MODELS in urls file RetrieveAutocompleteResultsApiView.as_view(autocomplete_config=AUTOCOMPLETE_MODELS).

Or use mixin drf_complete_autocomplete.views.RetrieveAutocompleteResultsMixin to create your own view.

License

The DRF complete autocomplete package is licensed under the FreeBSD License.

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

drf-complete-autocomplete-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file drf-complete-autocomplete-1.0.0.tar.gz.

File metadata

  • Download URL: drf-complete-autocomplete-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for drf-complete-autocomplete-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e58ccda6313b82eeec6f7d36883b60d0b7d7c33aa6eefa12993e301abbdab689
MD5 76d960fe1b68b7e13d21f0e1dd18a126
BLAKE2b-256 db4b1f73608a96912d3dda10f3a6620b1c98489b517a0fc7ebd0e34dfa098013

See more details on using hashes here.

Provenance

File details

Details for the file drf_complete_autocomplete-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: drf_complete_autocomplete-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for drf_complete_autocomplete-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 803d6d37ebf2035db5542ce92012e0845c35db9df0d1552145e55f2c8ac153e8
MD5 f8e881fea8b84d17376372dec0069d48
BLAKE2b-256 82173e42f60a2e0605ad7023af7684aa4666bde957c5b200ed67afdb2c6bf6eb

See more details on using hashes here.

Provenance

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