Skip to main content

Tweaks for existing built-in Django"s autocomplete feature

Project description


This simple django app enables users to do a few tweaks to Django's built-in autocomplete feature.


pip install django-simple-select2


class Publication(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):

class Reporter(models.Model):
    full_name = models.CharField(max_length=50)
    email = models.EmailField()

    def __str__(self):
        return self.full_name

class Article(models.Model):
    headline = models.CharField(max_length=100)
    pub_date = models.DateField()
    publications = models.ManyToManyField(Publication)
    reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)

    def __str__(self):
        return self.headline

from django.contrib import admin
from .models import Article
from simple_select2 import Select2Admin, AutoCompleteSelect2, AutoCompleteSelect2Multiple

class ArticleModelAdmin(Select2Admin, admin.ModelAdmin):
    extra = {
        'publications': AutoCompleteSelect2Multiple(url='select2-publication-list'),
        'reporter': AutoCompleteSelect2(url='select2-reporter-list')
    }, ArticleModelAdmin)
from simple_select2 import AutoCompleteBaseView
from .models import Reporter, Publication

class ReporterView(AutoCompleteBaseView):
    model = Reporter
    search_fields = ('full_name', 'email')

class PublicationView(AutoCompleteBaseView):
    model = Publication
    search_fields = ('name',)
from django.urls import path
from .views import ReporterView, PublicationView

urlpatterns = [
    path('reporter/', ReporterView.as_view(), name='select2-reporter-list'),
    path('publication/', PublicationView.as_view(), name='select2-publication-list'),

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-simple-select2-0.1.0.tar.gz (4.2 kB view hashes)

Uploaded source

Built Distributions

django_simple_select2-0.1-py3.6.egg (9.4 kB view hashes)

Uploaded 3 6

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page