A package supplying tools for easy creating autocompletes with drf.
Project description
DRF complete autocomplete
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | e58ccda6313b82eeec6f7d36883b60d0b7d7c33aa6eefa12993e301abbdab689 |
|
MD5 | 76d960fe1b68b7e13d21f0e1dd18a126 |
|
BLAKE2b-256 | db4b1f73608a96912d3dda10f3a6620b1c98489b517a0fc7ebd0e34dfa098013 |
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 803d6d37ebf2035db5542ce92012e0845c35db9df0d1552145e55f2c8ac153e8 |
|
MD5 | f8e881fea8b84d17376372dec0069d48 |
|
BLAKE2b-256 | 82173e42f60a2e0605ad7023af7684aa4666bde957c5b200ed67afdb2c6bf6eb |