From 604cd7fe14026da97f73fdb47dc48429b001290a Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Fri, 15 Jul 2005 20:37:03 +0000 Subject: [PATCH] Yes yes yes -- more documentation improvements git-svn-id: http://code.djangoproject.com/svn/django/trunk@67 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/db-api.txt | 42 +++++++++++- docs/faq.txt | 40 ++++++++--- docs/model-api.txt | 168 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 223 insertions(+), 27 deletions(-) diff --git a/docs/db-api.txt b/docs/db-api.txt index f96b3ebca8..54a704d3f0 100644 --- a/docs/db-api.txt +++ b/docs/db-api.txt @@ -305,4 +305,44 @@ objects fields, then call the object's ``save()`` method:: Creating new objects ==================== -... \ No newline at end of file +Creating new objects (i.e. ``INSERT``) is done by creating new instances +of objects then calling save() on them:: + + >>> p = polls.Poll(id=None, + ... slug="eggs", + ... question="How do you like your eggs?", + ... pub_date=datetime.datetime.now(), + ... expire_date=some_future_date) + >>> p.save() + +Calling ``save()`` on an object with an id if ``None`` signifies to +Django that the object is new and should be inserted. + +Related objects (i.e. ``Choices``) are created using convience functions:: + + >>> p.add_choice(choice="Over easy", votes=0) + >>> p.add_choice(choice="Scrambled", votes=0) + >>> p.add_choice(choice="Fertilized", votes=0) + >>> p.add_choice(choice="Poached", votes=0) + >>> p.get_choice_count() + 4 + +Each of those ``add_choice`` methods is equivilent to (except obviously much +simpler than):: + + >>> c = polls.Choice(id=None, + ... poll_id=p.id, + ... choice="Over easy", + ... votes=0) + >>> c.save() + +Note that when using the `add_foo()`` methods, you do not give any value +for the ``id`` field, nor do you give a value for the field that stores +the relation (``poll_id`` in this case). + +Deleting objects +================ + +Just cause we're crazy like that, the delete method is named ``delete()``. +Yeah, you never know what we're going to do next. + diff --git a/docs/faq.txt b/docs/faq.txt index 0afd3f52dc..0f2cbd0b42 100644 --- a/docs/faq.txt +++ b/docs/faq.txt @@ -66,12 +66,12 @@ Lawrence, Kansas, USA. `chicagocrime.org`_. `Simon Willison`_ - Simon is a well-respected Web developer from England. He had a one-year stint - at World Online, during which time he and Adrian developed Django from scratch. - He's enthusiastic, he's passionate about best practices in Web development, and - he really likes squirrels. Probably to a fault. He went back to England to - finish his degree and is poised to continue doing big, exciting things on the Web. - Read his weblog at `simon.incutio.com`_. + Simon is a well-respected Web developer from England. He had a one-year + stint at World Online, during which time he and Adrian developed Django from + scratch. He's enthusiastic, he's passionate about best practices in Web + development, and he really likes squirrels. Probably to a fault. He went + back to England to finish his degree and is poised to continue doing big, + exciting things on the Web. Read his weblog at `simon.incutio.com`_. `Jacob Kaplan-Moss`_ Jacob is a whipper-snapper from California who spends equal time coding and @@ -102,17 +102,35 @@ How do I get started? We're working on this documentation as you read this. +What are Django's prerequisites? +-------------------------------- + +Django requires Python_ 2.3 or later, Apache2_, and mod_python_. You'll +also need a database engine; PostgreSQL_ is recommended, and MySQL_ is +supported. + +We're currently working on expanding those options: WSGI_ support is in the +works (which will allow Django to run under CGI, FCGI, etc.), as is support for +a number of other database backends. + +.. _Python: http://www.python.org/ +.. _Apache2: http://httpd.apache.org/ +.. _mod_python: http://www.modpython.org/ +.. _PostgreSQL: http://www.postgresql.org/ +.. _MySQL: http://www.mysql.com/ +.. _WSGI: http://www.python.org/peps/pep-0333.html + The admin interface =================== The dynamically-generated admin site is ugly! How can I change it? ------------------------------------------------------------------ -We think it's very purty, but if you don't agree, you can modify the admin site's -presentation by editing the CSS stylesheet and/or associated image files. The -site is built using semantic HTML, so any changes you'd like to make should be -possible by editing the CSS stylesheet. We've got a `guide to the CSS used -in the admin`_ to get you started. +We think it's very purty, but if you don't agree, you can modify the admin +site's presentation by editing the CSS stylesheet and/or associated image files. +The site is built using semantic HTML, so any changes you'd like to make should +be possible by editing the CSS stylesheet. We've got a `guide to the CSS used in +the admin`_ to get you started. .. _`guide to the CSS used in the admin`: http://www.djangoproject.com/documentation/admin_css/ diff --git a/docs/model-api.txt b/docs/model-api.txt index d181bb868c..e4d059d1c1 100644 --- a/docs/model-api.txt +++ b/docs/model-api.txt @@ -180,8 +180,6 @@ options that are common to all field types. These options are: ``null`` If ``True`` empty values in the field will be stored as ``NULL`` in the database. - - XXX does null imply blank? XXX ``primary_key`` If ``True`` this field is the primary key for the table. You only need to use this if you don't want @@ -302,8 +300,8 @@ Field Types meta.ForeignKey(Pizza) - ``ForeignKey`` fields take a large number of options for defining how the - relationship should work: + ``ForeignKey`` fields take a large number of extra options for defining how + the relationship should work: ======================= ============================================================ Option Description @@ -364,7 +362,7 @@ Field Types Not used with ``edit_inline``. - ``rel_name`` The name of the relation. In the above exmaple, + ``rel_name`` The name of the relation. In the above example, this would default to 'pizza' (so that the ``Toppings`` object would have a ``get_pizza()`` function; if you set ``rel_name`` to "pie", then @@ -431,12 +429,60 @@ Field Types An IP address, in string format (i.e. "24.124.1.30"). ``ManyToManyField`` - XXX document once Adrian reworks this XXX + A many-to-many relation to another object. For example (taken from the + ``core.flatfiles`` object:: + class FlatFile(meta.Model): + fields = ( + ... + meta.ManyToManyField(Site), + ) + + Many-to-many relations are a bit different from other fields. First, they + aren't actually a field per se since they use a intermediary join table. + Second, they don't take any of the same options as the rest of the fields, + the only options taken are: + + ======================= ============================================================ + Option Description + ======================= ============================================================ + ``related_name`` See the description of ``related_name`` in + ``ManyToOneField``, above. + + ``filter_interface`` Use a nifty unobtrusive Javascript "filter" interface + instead of the usability-challenged ``