diff options
| author | Justin Bronn <jbronn@gmail.com> | 2008-02-28 21:24:51 +0000 |
|---|---|---|
| committer | Justin Bronn <jbronn@gmail.com> | 2008-02-28 21:24:51 +0000 |
| commit | 22e016ff6c18a35a450519b94de63033f83e6b4f (patch) | |
| tree | 1e58cc40a636b4e4f3dcf429a5a116c015c36278 /docs/model-api.txt | |
| parent | 0b52413cc926446f238fd781b4def6804f64d231 (diff) | |
gis: Merged revisions 7105-7168 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7176 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/model-api.txt')
| -rw-r--r-- | docs/model-api.txt | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/docs/model-api.txt b/docs/model-api.txt index 3f908ec158..66fa63e3c6 100644 --- a/docs/model-api.txt +++ b/docs/model-api.txt @@ -384,7 +384,7 @@ The admin represents this as an ``<input type="text">`` (a single-line input). ``IPAddressField`` ~~~~~~~~~~~~~~~~~~ -An IP address, in string format (i.e. "24.124.1.30"). +An IP address, in string format (e.g. "192.0.2.30"). The admin represents this as an ``<input type="text">`` (a single-line input). @@ -784,9 +784,17 @@ you can use the name of the model, rather than the model object itself:: class Manufacturer(models.Model): # ... -Note, however, that you can only use strings to refer to models in the same -models.py file -- you cannot use a string to reference a model in a different -application, or to reference a model that has been imported from elsewhere. +Note, however, that this only refers to models in the same models.py file -- you +cannot use a string to reference a model defined in another application or +imported from elsewhere. + +**New in Django development version:** to refer to models defined in another +application, you must instead explicitially specify the application label. That +is, if the ``Manufacturer`` model above is defined in another application called +``production``, you'd need to use:: + + class Car(models.Model): + manufacturer = models.ForeignKey('production.Manufacturer') Behind the scenes, Django appends ``"_id"`` to the field name to create its database column name. In the above example, the database table for the ``Car`` @@ -952,10 +960,10 @@ the relationship should work. All are optional: ``limit_choices_to`` See the description under ``ForeignKey`` above. ``symmetrical`` Only used in the definition of ManyToManyFields on self. - Consider the following model: + Consider the following model:: - class Person(models.Model): - friends = models.ManyToManyField("self") + class Person(models.Model): + friends = models.ManyToManyField("self") When Django processes this model, it identifies that it has a ``ManyToManyField`` on itself, and as a result, it @@ -1872,7 +1880,7 @@ more simply as:: If you define a ``__unicode__()`` method on your model and not a ``__str__()`` method, Django will automatically provide you with a ``__str__()`` that calls -``__unicode()__`` and then converts the result correctly to a UTF-8 encoded +``__unicode__()`` and then converts the result correctly to a UTF-8 encoded string object. This is recommended development practice: define only ``__unicode__()`` and let Django take care of the conversion to string objects when required. |
