21 | | {{{ |
| 21 | * [http://dojotoolkit.org Dojo 0.3.1] - used for AJAX and widget implementation. |
| 22 | * The [http://code.djangoproject.com/attachment/wiki/AJAXWidgetComboBox/nongselect-1.0.tar.gz NongSelect 1.0 widget tarball] attached to this page. |
| 23 | |
| 24 | |
| 25 | == Installation == |
| 26 | |
| 27 | * Install Dojo in media/js. |
| 28 | * Untar nongselect-1.0.tar.gz and copy the {{{nong}}} directory into the same parent directory as dojo and copy the contents of {{{views.py}}} into one of your own {{{views.py}}} files. |
| 29 | |
| 30 | My project layout is as follows: |
| 31 | |
| 32 | {{{ |
| 33 | myproject/ |
| 34 | myapp/ |
| 35 | models.py |
| 36 | views.py |
| 37 | urls.py |
| 38 | templatetags/ |
| 39 | formtags.py |
| 40 | templates/ |
| 41 | myapp/ |
| 42 | mymodel_form.html |
| 43 | widget/ |
| 44 | fieldrow.html |
| 45 | selectrow.html |
| 46 | media/ |
| 47 | js/ |
| 48 | dojo/ |
| 49 | nong/ |
| 50 | }}} |
| 51 | |
| 52 | |
| 53 | == Example Use == |
| 54 | |
| 55 | In this example we will create a form that uses the Select widget to for the Article's reporter field in below. |
| 56 | |
| 57 | === Model === |
| 58 | Using the example model from [http://www.djangoproject.com/documentation/models/many_to_one/ Model Examples]: |
| 59 | |
| 60 | {{{ |
| 61 | #!python |
| 62 | from django.db import models |
| 63 | |
| 64 | class Reporter(models.Model): |
| 65 | first_name = models.CharField(maxlength=30) |
| 66 | last_name = models.CharField(maxlength=30) |
| 67 | email = models.EmailField() |
| 68 | |
| 69 | def __str__(self): |
| 70 | return "%s %s" % (self.first_name, self.last_name) |
| 71 | |
| 72 | class Article(models.Model): |
| 73 | headline = models.CharField(maxlength=100) |
| 74 | pub_date = models.DateField() |
| 75 | reporter = models.ForeignKey(Reporter) |
| 76 | |