Skip to main content

Tweaks for existing built-in Django"s autocomplete feature

Project description

django-simple-select2

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

Installation

pip install django-simple-select2

Usage

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

    def __str__(self):
        return self.name


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

# admin.py
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')
    }


admin.site.register(Article, ArticleModelAdmin)

#views.py
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',)

#urls.py
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 details)

Uploaded Source

Built Distributions

django_simple_select2-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

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

Uploaded Source

File details

Details for the file django-simple-select2-0.1.0.tar.gz.

File metadata

  • Download URL: django-simple-select2-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for django-simple-select2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b5c81cbbb7346f7515749e2e625dfaa41223cbc346c27a39371d7e09b7636a2
MD5 2ee924f037e2a88190a1ffd6c5c4f742
BLAKE2b-256 cf7aac20852bb879c4dfbd04d118941c087138f0cf9079efea692fef9f495dd2

See more details on using hashes here.

File details

Details for the file django_simple_select2-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_simple_select2-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for django_simple_select2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a90f658b9c7a67eedb06715324dafca46fba73f037bba19f6180edccefd2e3c
MD5 bf21f70fadf16cc0ab10f728f1d76ab8
BLAKE2b-256 f3f404a7ed640b3a4f75bc856284ed04f86a6de6878071b3950af4107a37ec08

See more details on using hashes here.

File details

Details for the file django_simple_select2-0.1-py3.6.egg.

File metadata

  • Download URL: django_simple_select2-0.1-py3.6.egg
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for django_simple_select2-0.1-py3.6.egg
Algorithm Hash digest
SHA256 01079038663afb5ec00b794c94c512d85629369a690d0e550f897c443971a042
MD5 17c14f6c224f3406e02da22ee6057809
BLAKE2b-256 baaabe22e7748520022c260600c903939de6e4bbd5186c6e1b8a3da7ea4acf61

See more details on using hashes here.

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