All Projects → Starou → django-yaaac

Starou / django-yaaac

Licence: other
Ajax Autocomplete Django application

Programming Languages

python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language
CSS
56736 projects
Makefile
30231 projects
HTML
75241 projects

Projects that are alternatives of or similar to django-yaaac

MentionMe
A plugin for MyBB 1.8.x that allows Twitter-style tagging and integration with MyAlerts
Stars: ✭ 19 (+46.15%)
Mutual labels:  autocomplete
django-code-generator
Generate code from your Django models for faster development
Stars: ✭ 35 (+169.23%)
Mutual labels:  django-admin
autofill
Bookmarklet to fill out forms when testing by simply clicking on it.
Stars: ✭ 54 (+315.38%)
Mutual labels:  autocomplete
django-sqlalchemy
Django ORM built on top of SQLalchemy core 2.0 for seamless integration of SQLAlchemy with Django 4.1+ PostgreSQL 14+ only for now. [pre POC now]
Stars: ✭ 101 (+676.92%)
Mutual labels:  django-admin
python-tools
🔧 Atom plugin which uses jedi to provide numerous tools useful for developing python code in atom.
Stars: ✭ 96 (+638.46%)
Mutual labels:  autocomplete
tabnine-atom
Atom client for Tabnine - Code Faster with the All-Language AI Assistant for Code Completion, autocomplete JavaScript, Python, TypeScript, PHP, Go, Java, node.js, Ruby, C/C++, HTML/CSS, C#, Rust, SQL, Bash, Kotlin, React, Swift, Scala, Sass, Perl, Objective C, Node JS, Matlab, Haskell, Dart, Angular. https://atom.io/packages/tabnine
Stars: ✭ 33 (+153.85%)
Mutual labels:  autocomplete
dt-sql-parser
SQL Parsers for BigData, built with antlr4.
Stars: ✭ 135 (+938.46%)
Mutual labels:  autocomplete
VSLilyPond
VSCode Extension for LilyPond
Stars: ✭ 59 (+353.85%)
Mutual labels:  autocomplete
sora-editor
A cool code editor library on Android with syntax-highlighting and auto-completion. (aka CodeEditor)
Stars: ✭ 580 (+4361.54%)
Mutual labels:  autocomplete
CLI-Autocomplete
Cross-platform flexible autocomplete library for your CLI applications.
Stars: ✭ 21 (+61.54%)
Mutual labels:  autocomplete
angular-search-experience
Algolia + Angular = 🔥🔥🔥
Stars: ✭ 166 (+1176.92%)
Mutual labels:  autocomplete
AutoCompleteTextField
AutoCompleteTextField for OS X
Stars: ✭ 68 (+423.08%)
Mutual labels:  autocomplete
addressr
Free Australian Address Validation, Search and Autocomplete
Stars: ✭ 46 (+253.85%)
Mutual labels:  autocomplete
GoogleMapsHelper
An easy to integrate Model Based Google Maps Helper (SVHTTPClient, AFNetworking) That lets you Geo Code , Reverse Geocode, Get Directions , Places Autocomplete.
Stars: ✭ 21 (+61.54%)
Mutual labels:  autocomplete
tern-openui5
🛠 Autocomplete for the OpenUI5 framework for your favorite code editor, powered by Tern.
Stars: ✭ 26 (+100%)
Mutual labels:  autocomplete
react-thailand-address-typeahead
jquery.Thailand.js in React
Stars: ✭ 78 (+500%)
Mutual labels:  autocomplete
VPAutoComplete
A simple Auto Complete UITextField also support UITableView written in swift 4.2
Stars: ✭ 20 (+53.85%)
Mutual labels:  autocomplete
fast-autocomplete
Fast Autocomplete: When Elastcsearch suggestions are not fast and flexible enough
Stars: ✭ 201 (+1446.15%)
Mutual labels:  autocomplete
react-abstract-autocomplete
Bring-Your-Own-UI autocomplete / mentions component for React.
Stars: ✭ 15 (+15.38%)
Mutual labels:  autocomplete
elixir auto complete
Bash Autocompletion for elixir, iex and mix
Stars: ✭ 21 (+61.54%)
Mutual labels:  autocomplete

Another Ajax Auto-Complete, Yet

https://coveralls.io/repos/Starou/django-yaaac/badge.png Supported Python versions License Travis C.I.

Yaaac is lightweight Django application providing Ajax search to foreign-key form fields.

Version 3 upgrade warning

This version brings Python 3.6 compatibility with a minor regression. The default suggest_by is now __str__ instead of __unicode__ so check the Django documentation to migrate your code.

Django 2-2 and Version 3.2 important note

Since Django-2.2 the way assets are sorted has been completely rewritten and as the result breaks this lib in the admin. The fix was to embbed jQuery and set the dependency in the widgets Media classes which may leads to other regressions.

Since a autocomplete solution is now built-in Django admin, the support for the admin has been removed.

Installation

Install the app from the source:

python setup.py build && (sudo) python setup.py install

Or with pip:

pip install django-yaaac

(for Django < 1.8, use a previous version like pip install django-yaaac==1.9.0)

Add the app in your settings.INSTALLED_APPS:

INSTALLED_APPS = [
    ...,
    "django_yaaac",
    ...,
]

In the urls.py module of your project, define the url pattern for ajax calls:

from django_yaaac.manager import autocomplete
from django.conf.urls import url

urlpatterns = [
    ...
    url(r'^yaaac/', autocomplete.urls),
    ...
]

Usage

Forms

What you need to do is to declare a custom ModelForm:

from django import forms
from django.contrib import admin
from django_yaaac.forms.fields import AutocompleteModelChoiceField
from . import models


class BandMemberForm(forms.ModelForm):
    band = AutocompleteModelChoiceField(site=admin.site,
                                        queryset=models.Band.objects.all(),
                                        yaaac_opts={
                                            "search_fields": ["^name"],
                                            "suggest_by": "get_full_name",
                                            "min_chars": 3,    # Fire search when 3 chars are sent (1 by default.)
                                            "max_height": 400, # 300px by default.
                                            "width": 250,      # 300px by default.
                                        },
                                        required=True)
    class Meta:
        model = models.BandMember

    class Media:
        # You need jQuery. Don't forget to call {{ form.media }} in your template.
        js = ('js/jquery.min.js', )


admin.site.register(models.BandMember, BandMemberAdmin)

The site parameter of AutocompleteModelChoiceField is required for related lookup (the magnifier glass). The search_fields is a list of fields to search against using the same syntax as in Django Admin (^, $ etc). Extra options min_chars, max_height and width are the counter-part of minChars, maxHeight and width in Autocomplete options.

suggest_by is optional. It can be a field or a method of the model. By default, suggestions are shown using __unicode__ method.

If your model define a get_absolute_url() method, the label is a link to that resource.

Models

The Yaaac class must defines the following:

  • user_passes_test is a class method that takes a user and return True or False.
  • allows_suggest_by is a list of model fields or methods that can used as return value by the search view.
class BandMember(models.Model):
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    band = models.ForeignKey("Band", null=True, blank=True)
    favorite_instrument = models.ForeignKey("Instrument", null=True, blank=True)

    class Meta:
        unique_together = (('first_name', 'last_name'),)

    class Yaaac:
        user_passes_test = lambda instance, user: user and user.is_authenticated() or False
        allows_suggest_by = ['get_full_name']

    def __unicode__(self):
        return u"%s %s" % (self.first_name, self.last_name)

    def get_full_name(self):
        return u"%s %s" % (self.first_name, self.last_name)

Tuning

To ease the DOM manipulation, HTML classes are added to the elements. The most interesting being yaaac_<fieldname> to the hidden input storing the foreign key value. This is very convenient when you need to add behavior to a whole set of fields - also those that don't exist when the page is created - sharing the same name.

Use jQuery delegation (i.e. $(".foo").on("change", ".yaaac_first_name")) to place an event on one field for all the inline forms present in the page or to come (i.e. Click on "Add a new Band Member".)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].