A django app that provides suggestions while you type into the field.
Project description
Django Awesomplete
A django app that provides suggestions while you type into the field.
Requirements
- Python 3.4+
- Django 1.11+
Quickstart
Lets assume we are making a cities app in django and our models.py
is:
from django.db import models
class City(models.Model):
name = models.CharField(max_length=255)
country = models.CharField(max_length=255)
def __str__(self):
return self.name
To use suggestions we need to override widget in admin.py
:
from django import forms
from django.contrib import admin
from awesomplete.widgets import AwesompleteWidget
from .models import City
def get_country_suggestions():
"""
Get a suggestions list from existing records.
"""
return City.objects.values_list(
'country', flat=True
).order_by('country').distinct()
class CityAdminForm(forms.ModelForm):
class Meta:
model = City
fields = forms.ALL_FIELDS
widgets = {
'country': AwesompleteWidget(
suggestions=get_country_suggestions
)
}
@admin.register(City)
class CityAdmin(admin.ModelAdmin):
form = CityAdminForm
Result:
Installation
Install the desired version with pip:
pip install django-awesomplete
Then add awesomplete to INSTALLED_APPS in your settings file:
INSTALLED_APPS = (
# ...
'awesomplete',
# ...
)
Links
- awesomplete created by Lea Verou.
License
Copyright (c) 2018 Mihail Mishakin Released under the BSD license (see 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
Close
Hashes for django_awesomplete-0.1.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08cb1bd6a3078b9dac9d0d761583f85dee96b36e3f9e58361254647b0cc9165a |
|
MD5 | de236ee37a5f01e6d013f6a903427e35 |
|
BLAKE2b-256 | 9290fe50f2c347eb0d2bd59fd2ac30068d12f27589ad021c10af390c9f5b4022 |