Changes between Initial Version and Version 1 of AJAXForeignKey


Ignore:
Timestamp:
May 20, 2007, 3:43:09 PM (18 years ago)
Author:
Michael Axiak <axiak@…>
Comment:

Created the page

Legend:

Unmodified
Added
Removed
Modified
  • AJAXForeignKey

    v1 v1  
     1= !AjaxForeignKey Field =
     2
     3== The Problem ==
     4In the Admin, I would like to have an autocompletion field for !ForeignKey references. I know raw-id-admin works, but AJAX is just so much cooler.
     5
     6== The Solution ==
     7=== Overview ===
     8Using [http://developer.yahoo.com/yui/ YUI], create a new field similar to {{{models.ForeignKey}}} that renders differently in the admin.
     9
     10== Installation ==
     11
     12Here's how it's setup:
     13
     141. Create a new folder in your project called {{{ajaxfkey }}}
     15
     162. Create three files in that directory:
     17
     18  * {{{__init__.py}}} -- duh
     19  * {{{fields.py}}} -- contains the actual model field. (download)
     20  * {{{forms.py}}}  -- contains the form field. (download)
     213. Create a {{{base_site.html}}} file in your {{{base_templates/admin}}} directory.
     22
     234. Modify your models to use it correctly.
     24
     25=== {{{ base_templates/admin/base_site.html }}} ===
     26
     27{{{
     28{% extends "admin/base.html" %}
     29{% load i18n %}
     30
     31{% block extrahead %}{{ block.super }}
     32<script type="text/javascript" src="/media/scripts/yui/yahoo/yahoo-min.js"></script>
     33<script type="text/javascript" src="/media/scripts/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
     34<script type="text/javascript" src="/media/scripts/yui/dom/dom-min.js"></script>
     35<script type="text/javascript" src="/media/scripts/yui/connection/connection-min.js"></script>
     36<script type="text/javascript" src="/media/scripts/yui/animation/animation-min.js"></script>
     37<script type="text/javascript" src="/media/scripts/yui/autocomplete/autocomplete-min.js"></script>
     38<script type="text/javascript" src="/media/scripts/json.js"></script>
     39{% endblock %}
     40
     41{% block title %}{{ title|escape }} | {% trans 'Django site admin' %}{% endblock %}
     42
     43{% block branding %}
     44<h1 id="site-name">{% trans 'Django administration' %}</h1>
     45{% endblock %}
     46
     47{% block nav-global %}{% endblock %}
     48}}}
     49
     50Notice how YUI is in {{{"/media/scripts/yui"}}} and I downloaded [http://www.json.org/json.js json.js]
Back to Top