AdminΒΆ

If your application does not otherwise require a custom Form class then you can create the form directly in your admin using make_ajax_form

ajax_select.helpers.make_ajax_form(model, fieldlist, superclass=<class 'django.forms.models.ModelForm'>, show_help_text=False, **kwargs)

Creates a ModelForm subclass with AutoComplete fields.

Parameters:
  • model (type) – Model class for which you are making the ModelForm
  • fieldlist (dict) – {field_name -> channel_name, ...}
  • superclass (type) – optional ModelForm superclass
  • show_help_text (bool) – suppress or show the widget help text
Returns:

a ModelForm suitable for use in an Admin

Return type:

ModelForm

Usage:

from django.contrib import admin
from ajax_select import make_ajax_form
from yourapp.models import YourModel

@admin.register(YourModel)
class YourModelAdmin(Admin):

    form = make_ajax_form(YourModel, {
        'contacts': 'contact',  # ManyToManyField
        'author':'contact'      # ForeignKeyField
    })

Where ‘contacts’ is a ManyToManyField specifying to use the lookup channel ‘contact’ and ‘author’ is a ForeignKeyField specifying here to also use the same lookup channel ‘contact’