Giter VIP home page Giter VIP logo

django-chosen-ajax's Introduction

Author: Eric Honkanen <[email protected]>
Version: 0.1.0

Overview

http://i.imgur.com/wK54oJF.jpg?3

django-chosen-ajax implements the chosen javascript library into the django admin for select form elements. It also implements ajax autocomplete functionality for form fields which have large numbers of related objects. The library currently uses jquery and was inspired by django-chosen and chosen-ajax.

Features

  • Integrates chosen into the admin
  • Implements ajax functionality for ModelMultipleChoiceField's

Install

Install with pip

pip install git+https://github.com/epicowl/django-chosen-ajax.git#egg=django-chosen-ajax

Add chosen to your INSTALLED_APPS

Run collectstatic

Compatibility

django-chosen-ajax has been tested with

Django:1.4, 1.5
Python:2.7
Database:PostgreSQL

Usage

Subclass the ChosenAdminForm using the ChosenAjaxField for ajax fields and include the required search_fields=('field',) where field is the name of a database field to use for the search lookup.

from chosen.forms import ChosenAdminForm
from chosen.fields import ChosenAjaxField


class PonyForm(ChosenAdminForm):
    ponies = ChosenAjaxField(
        required=False,
        queryset=Pony.objects.all(),
        search_fields=('name', 'breed',)
    )

    class Meta:
        model = YourModel

Currently you will also have to add the admin site to your ModelAdmin to make the green add related button work.

from django.contrib import admin
from ponyapp.forms import PonyForm


class PonyAdmin(admin.ModelAdmin):
    form = PonyForm

    def __init__(self, model, admin_site):
        super(PonyAdmin, self).__init__(model, admin_site)
        self.form.admin_site = admin_site

You can add as many fields to search_fields as you need, they get combined into a lookup. Everything else is automatic and handled in the ChosenAdminForm.

Hit me up if you have questions or want to contribute!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.