My favorites | Sign in
Project Home
Search
for
AdminExtensions  
Current Field Extensions
Featured, Extensions
Updated Feb 4, 2010 by leidel

Current Admin Extensions

  • ForeignKeyAutocompleteAdmin - ForeignKeyAutocompleteAdmin will enable the admin app to show ForeignKey fields with an search input field. The search field is rendered by the ForeignKeySearchInput form widget and uses jQuery to do configureable autocompletion.
You can watch a small demo at Flickr: http://www.flickr.com/photos/jannis/3246408003/
Comment by ce.lo...@gmail.com, Mar 12, 2009

This is very cool and helpful - so is the Jannis' post in his blog about doing autocompletion on the admin interface.

But could we have some instructions on how to set up and use ForeignKeyAutocompleteAdmin??

In my admin.py I did something like this:

import django_extensions class TravelLogClientAdmin?(django_extensions.admin.ForeignKeyAutocompleteAdmin?):

related_search_fields = {
'company': ('company',)
}
admin.site.register(TravelLogClient?, TravelLogClientAdmin?)

But I fail to understand how to configure my app to properly serve the django-extensions media...

Comment by michele.pasin, Sep 29, 2009

in my case all I had to do was to put the django_extensions/media folder in my usual media location..

Comment by ahernp....@gmail.com, Dec 1, 2010

I found it difficult to figure out how to install and use this extension (the demo at flicker seems to be gone). So here are some step-by-step instructions based on what worked for me.

ForeignKeyAutocompleteAdmin

Django Command Extensions includes a new ModelAdmin class called ForeignKeyAutocompleteAdmin which can be used to add a search function to ForeignKey fields on Admin pages. Here is how to set up and use it.

Example models for Authors and Books:

from django.db import models

class Author(models.Model):
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

class Book(models.Model)
    title = models.CharField(max_length=100)
    author = models.ForeignKey(Author)

Install Django Command Extensions.

Make sure that the Django Extensions media folder is available in the MEDIA_ROOT directory of your Django settings.py.

Add searching for Authors to the admin of the Book model by extending the new ForeignKeyAutocompleteAdmin? class and adding a dictionary called related_search_fields where the key is the ForeignKey and the value is a list of fields to search on in Author model:

from django.contrib import admin
from django_extensions.admin import ForeignKeyAutocompleteAdmin

class BookAdmin(ForeignKeyAutocompleteAdmin):
    related_search_fields = {
                            'author': ('first_name', 'last_name')
                            }

admin.site.register(Book, BookAdmin)

This creates an Admin interface with two text input fields, separated by a search icon [M]. Text entered in the first field is used to search for matching Author objects. The second field contains the primary key id of the selected object. The search icon opens a popup window to do the searching, if preferred. On the line the text fields are instructions on how to use them.

Author: ______ [M] _____     
        Use the left field to do Author lookups in the fields first_name and last_name.
Comment by kevo1cat...@gmail.com, Jan 5, 2012

Author: M? Use the left field to do Author lookups in the fields first_name and last_name.


Sign in to add a comment
Powered by Google Project Hosting