Skip to main content

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

License

Copyright (c) 2018 Mihail Mishakin Released under the BSD license (see 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

django-awesomplete-0.1.5.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

django_awesomplete-0.1.5-py2.py3-none-any.whl (22.6 kB view hashes)

Uploaded Python 2 Python 3

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