From 8013f76a40270283f9d3c04160ac9b8a72ffe2be Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 11 Jan 2006 05:07:38 +0000 Subject: magic-removal: Merged to [1903] git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1904 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/tutorial02.txt | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'docs/tutorial02.txt') diff --git a/docs/tutorial02.txt b/docs/tutorial02.txt index 21454523d0..c7a38f8a01 100644 --- a/docs/tutorial02.txt +++ b/docs/tutorial02.txt @@ -31,7 +31,7 @@ The Django admin site is not activated by default -- it's an opt-in thing. To activate the admin site for your installation, do these three things: * Add ``"django.contrib.admin"`` to your ``INSTALLED_APPS`` setting. - * Run the command ``django-admin.py install admin``. This will create an + * Run the command ``python manage.py install admin``. This will create an extra database table that the admin needs. * Edit your ``myproject/urls.py`` file and uncomment the line below "Uncomment this for admin:". This file is a URLconf; we'll dig into @@ -43,28 +43,18 @@ Create a user account Run the following command to create a superuser account for your admin site:: - django-admin.py createsuperuser --settings=myproject.settings + python manage.py createsuperuser The script will prompt you for a username, e-mail address and password (twice). Start the development server ============================ -To make things easy, Django comes with a pure-Python Web server that builds on -the BaseHTTPServer included in Python's standard library. Let's start the -server and explore the admin site. +Let's start the development server and explore the admin site. -Just run the following command to start the server:: +Recall from Tutorial 1 that you start the development server like so:: - django-admin.py runserver --settings=myproject.settings - -It'll start a Web server running locally -- on port 8000, by default. If you -want to change the server's port, pass it as a command-line argument:: - - django-admin.py runserver 8080 --settings=myproject.settings - -DON'T use this server in anything resembling a production environment. It's -intended only for use while developing. + python manage.py runserver Now, open a Web browser and go to "/admin/" on your local domain -- e.g., http://127.0.0.1:8000/admin/. You should see the admin's login screen: @@ -91,8 +81,8 @@ Make the poll app modifiable in the admin But where's our poll app? It's not displayed on the admin index page. -Just one thing to do: We need to specify in the ``polls.Poll`` model that Poll -objects have an admin interface. Edit the ``myproject/apps/polls/models/polls.py`` +Just one thing to do: We need to specify in the ``Poll`` model that ``Poll`` +objects have an admin interface. Edit the ``myproject/polls/models/polls.py`` file and make the following change to add an inner ``Meta`` class with an ``admin`` attribute:: @@ -101,11 +91,13 @@ file and make the following change to add an inner ``Meta`` class with an class Meta: admin = meta.Admin() -The ``class Meta`` contains all non-field metadata about this model. +The ``class Meta`` contains all `non-field metadata`_ about this model. Now reload the Django admin page to see your changes. Note that you don't have to restart the development server -- it auto-reloads code. +.. _non-field metadata: http://www.djangoproject.com/documentation/model_api/#meta-options + Explore the free admin functionality ==================================== @@ -216,14 +208,14 @@ aren't commonly used:: Adding related objects ====================== -OK, we have our Poll admin page. But a ``Poll`` has multiple ``Choices``, and the admin -page doesn't display choices. +OK, we have our Poll admin page. But a ``Poll`` has multiple ``Choices``, and +the admin page doesn't display choices. Yet. -In this case, there are two ways to solve this problem. The first is to give -the ``Choice`` model its own ``admin`` attribute, just as we did with ``Poll``. -Here's what that would look like:: +There are two ways to solve this problem. The first is to give the ``Choice`` +model its own ``admin`` attribute, just as we did with ``Poll``. Here's what +that would look like:: class Choice(meta.Model): # ... @@ -237,7 +229,8 @@ looks like this: :alt: Choice admin page In that form, the "Poll" field is a select box containing every poll in the -database. In our case, only one poll exists at this point. +database. Django knows that a ``ForeignKey`` should be represented in the admin +as a ``