mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed a couple typos in the modeltests' descriptions and made use of ReST inline literal markup for code snippets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8325 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -11,7 +11,7 @@ query the database. | ||||
|  | ||||
| If you need to use a table name for a many-to-many relationship that differs | ||||
| from the default generated name, use the ``db_table`` parameter on the | ||||
| ManyToMany field. This has no effect on the API for querying the database. | ||||
| ``ManyToMany`` field. This has no effect on the API for querying the database. | ||||
|  | ||||
| """ | ||||
|  | ||||
| @@ -87,7 +87,7 @@ Traceback (most recent call last): | ||||
|     ... | ||||
| AttributeError: 'Author' object has no attribute 'last' | ||||
|  | ||||
| # Although the Article table uses a custom m2m table,  | ||||
| # Although the Article table uses a custom m2m table, | ||||
| # nothing about using the m2m relationship has changed... | ||||
|  | ||||
| # Get all the authors for an article | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| """ | ||||
| 42. Storing files according to a custom storage system | ||||
|  | ||||
| FileField and its variations can take a "storage" argument to specify how and | ||||
| where files should be stored. | ||||
| ``FileField`` and its variations can take a ``storage`` argument to specify how | ||||
| and where files should be stored. | ||||
| """ | ||||
|  | ||||
| import tempfile | ||||
|   | ||||
| @@ -5,7 +5,7 @@ Fixtures are a way of loading data into the database in bulk. Fixure data | ||||
| can be stored in any serializable format (including JSON and XML). Fixtures | ||||
| are identified by name, and are stored in either a directory named 'fixtures' | ||||
| in the application directory, on in one of the directories named in the | ||||
| FIXTURE_DIRS setting. | ||||
| ``FIXTURE_DIRS`` setting. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -2,8 +2,8 @@ | ||||
| 34. Generic relations | ||||
|  | ||||
| Generic relations let an object have a foreign key to any object through a | ||||
| content-type/object-id field. A generic foreign key can point to any object, | ||||
| be it animal, vegetable, or mineral. | ||||
| content-type/object-id field. A ``GenericForeignKey`` field can point to any | ||||
| object, be it animal, vegetable, or mineral. | ||||
|  | ||||
| The canonical example is tags (although this example implementation is *far* | ||||
| from complete). | ||||
| @@ -32,7 +32,7 @@ class Comparison(models.Model): | ||||
|     A model that tests having multiple GenericForeignKeys | ||||
|     """ | ||||
|     comparative = models.CharField(max_length=50) | ||||
|      | ||||
|  | ||||
|     content_type1 = models.ForeignKey(ContentType, related_name="comparative1_set") | ||||
|     object_id1 = models.PositiveIntegerField() | ||||
|  | ||||
| @@ -50,7 +50,7 @@ class Animal(models.Model): | ||||
|     latin_name = models.CharField(max_length=150) | ||||
|  | ||||
|     tags = generic.GenericRelation(TaggedItem) | ||||
|     comparisons = generic.GenericRelation(Comparison,  | ||||
|     comparisons = generic.GenericRelation(Comparison, | ||||
|                                           object_id_field="object_id1", | ||||
|                                           content_type_field="content_type1") | ||||
|  | ||||
|   | ||||
| @@ -2,10 +2,10 @@ | ||||
| 8. get_latest_by | ||||
|  | ||||
| Models can have a ``get_latest_by`` attribute, which should be set to the name | ||||
| of a DateField or DateTimeField. If ``get_latest_by`` exists, the model's | ||||
| manager will get a ``latest()`` method, which will return the latest object in | ||||
| the database according to that field. "Latest" means "having the date farthest | ||||
| into the future." | ||||
| of a ``DateField`` or ``DateTimeField``. If ``get_latest_by`` exists, the | ||||
| model's manager will get a ``latest()`` method, which will return the latest | ||||
| object in the database according to that field. "Latest" means "having the date | ||||
| farthest into the future." | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -1,13 +1,13 @@ | ||||
| """ | ||||
| 35. DB-API Shortcuts | ||||
|  | ||||
| get_object_or_404 is a shortcut function to be used in view functions for | ||||
| performing a get() lookup and raising a Http404 exception if a DoesNotExist | ||||
| exception was raised during the get() call. | ||||
| ``get_object_or_404()`` is a shortcut function to be used in view functions for | ||||
| performing a ``get()`` lookup and raising a ``Http404`` exception if a | ||||
| ``DoesNotExist`` exception was raised during the ``get()`` call. | ||||
|  | ||||
| get_list_or_404 is a shortcut function to be used in view functions for | ||||
| performing a filter() lookup and raising a Http404 exception if a DoesNotExist | ||||
| exception was raised during the filter() call. | ||||
| ``get_list_or_404()`` is a shortcut function to be used in view functions for | ||||
| performing a ``filter()`` lookup and raising a ``Http404`` exception if a | ||||
| ``DoesNotExist`` exception was raised during the ``filter()`` call. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
| @@ -16,7 +16,7 @@ from django.shortcuts import get_object_or_404, get_list_or_404 | ||||
|  | ||||
| class Author(models.Model): | ||||
|     name = models.CharField(max_length=50) | ||||
|      | ||||
|  | ||||
|     def __unicode__(self): | ||||
|         return self.name | ||||
|  | ||||
| @@ -29,7 +29,7 @@ class Article(models.Model): | ||||
|     title = models.CharField(max_length=50) | ||||
|     objects = models.Manager() | ||||
|     by_a_sir = ArticleManager() | ||||
|      | ||||
|  | ||||
|     def __unicode__(self): | ||||
|         return self.title | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,9 @@ | ||||
| """ | ||||
| 33. get_or_create() | ||||
|  | ||||
| get_or_create() does what it says: it tries to look up an object with the given | ||||
| parameters. If an object isn't found, it creates one with the given parameters. | ||||
| ``get_or_create()`` does what it says: it tries to look up an object with the | ||||
| given parameters. If an object isn't found, it creates one with the given | ||||
| parameters. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -4,10 +4,10 @@ | ||||
| For many-to-many relationships that need extra fields on the intermediary | ||||
| table, use an intermediary model. | ||||
|  | ||||
| In this example, an ``Article`` can have multiple ``Reporter``s, and each | ||||
| ``Article``-``Reporter`` combination (a ``Writer``) has a ``position`` field, | ||||
| which specifies the ``Reporter``'s position for the given article (e.g. "Staff | ||||
| writer"). | ||||
| In this example, an ``Article`` can have multiple ``Reporter`` objects, and | ||||
| each ``Article``-``Reporter`` combination (a ``Writer``) has a ``position`` | ||||
| field, which specifies the ``Reporter``'s position for the given article | ||||
| (e.g. "Staff writer"). | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| """ | ||||
| 20. Multiple many-to-many relationships between the same two tables | ||||
|  | ||||
| In this example, an Article can have many Categories (as "primary") and many | ||||
| Categories (as "secondary"). | ||||
| In this example, an ``Article`` can have many "primary" ``Category`` objects | ||||
| and many "secondary" ``Category`` objects. | ||||
|  | ||||
| Set ``related_name`` to designate what the reverse relationship is called. | ||||
| """ | ||||
|   | ||||
| @@ -1,15 +1,19 @@ | ||||
| """ | ||||
| 28. Many-to-many relationships between the same two tables | ||||
|  | ||||
| In this example, A Person can have many friends, who are also people. Friendship is a | ||||
| symmetrical relationship - if I am your friend, you are my friend. | ||||
| In this example, a ``Person`` can have many friends, who are also ``Person`` | ||||
| objects. Friendship is a symmetrical relationship - if I am your friend, you | ||||
| are my friend. Here, ``friends`` is an example of a symmetrical | ||||
| ``ManyToManyField``. | ||||
|  | ||||
| A person can also have many idols - but while I may idolize you, you may not think | ||||
| the same of me. 'Idols' is an example of a non-symmetrical m2m field. Only recursive | ||||
| m2m fields may be non-symmetrical, and they are symmetrical by default. | ||||
| A ``Person`` can also have many idols - but while I may idolize you, you may | ||||
| not think the same of me. Here, ``idols`` is an example of a non-symmetrical | ||||
| ``ManyToManyField``. Only recursive ``ManyToManyField`` fields may be | ||||
| non-symmetrical, and they are symmetrical by default. | ||||
|  | ||||
| This test validates that the m2m table will create a mangled name for the m2m table if | ||||
| there will be a clash, and tests that symmetry is preserved where appropriate. | ||||
| This test validates that the many-to-many table is created using a mangled name | ||||
| if there is a name clash, and tests that symmetry is preserved where | ||||
| appropriate. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| """ | ||||
| 27. Default manipulators | ||||
|  | ||||
| Each model gets an AddManipulator and ChangeManipulator by default. | ||||
| Each model gets an ``AddManipulator`` and ``ChangeManipulator`` by default. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| """ | ||||
| 5. Many-to-many relationships | ||||
|  | ||||
| To define a many-to-many relationship, use ManyToManyField(). | ||||
| To define a many-to-many relationship, use ``ManyToManyField()``. | ||||
|  | ||||
| In this example, an article can be published in multiple publications, | ||||
| and a publication has multiple articles. | ||||
| In this example, an ``Article`` can be published in multiple ``Publication`` | ||||
| objects, and a ``Publication`` has multiple ``Article`` objects. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| """ | ||||
| 4. Many-to-one relationships | ||||
|  | ||||
| To define a many-to-one relationship, use ``ForeignKey()`` . | ||||
| To define a many-to-one relationship, use ``ForeignKey()``. | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| """ | ||||
| XX. Generating HTML forms from models | ||||
|  | ||||
| This is mostly just a reworking of the form_for_model/form_for_instance tests | ||||
| to use ModelForm. As such, the text may not make sense in all cases, and the | ||||
| examples are probably a poor fit for the ModelForm syntax. In other words, | ||||
| most of these tests should be rewritten. | ||||
| This is mostly just a reworking of the ``form_for_model``/``form_for_instance`` | ||||
| tests to use ``ModelForm``. As such, the text may not make sense in all cases, | ||||
| and the examples are probably a poor fit for the ``ModelForm`` syntax. In other | ||||
| words, most of these tests should be rewritten. | ||||
| """ | ||||
|  | ||||
| import os | ||||
|   | ||||
| @@ -1,12 +1,12 @@ | ||||
| """ | ||||
| 19. OR lookups | ||||
|  | ||||
| To perform an OR lookup, or a lookup that combines ANDs and ORs, | ||||
| combine QuerySet objects using & and | operators. | ||||
| To perform an OR lookup, or a lookup that combines ANDs and ORs, combine | ||||
| ``QuerySet`` objects using ``&`` and ``|`` operators. | ||||
|  | ||||
| Alternatively, use positional arguments, and pass one or more expressions of | ||||
| clauses using the variable ``django.db.models.Q`` (or any object with an | ||||
| add_to_query method). | ||||
| ``add_to_query`` method). | ||||
| """ | ||||
| # Python 2.3 doesn't have sorted() | ||||
| try: | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  | ||||
| Specify default ordering for a model using the ``ordering`` attribute, which | ||||
| should be a list or tuple of field names. This tells Django how to order | ||||
| queryset results. | ||||
| ``QuerySet`` results. | ||||
|  | ||||
| If a field name in ``ordering`` starts with a hyphen, that field will be | ||||
| ordered in descending order. Otherwise, it'll be ordered in ascending order. | ||||
|   | ||||
| @@ -2,8 +2,8 @@ | ||||
| """ | ||||
| 42. Serialization | ||||
|  | ||||
| ``django.core.serializers`` provides interfaces to converting Django querysets | ||||
| to and from "flat" data (i.e. strings). | ||||
| ``django.core.serializers`` provides interfaces to converting Django | ||||
| ``QuerySet`` objects to and from "flat" data (i.e. strings). | ||||
| """ | ||||
|  | ||||
| from django.db import models | ||||
|   | ||||
| @@ -11,10 +11,10 @@ The server Response objects are annotated with the details | ||||
| of the contexts and templates that were rendered during the | ||||
| process of serving the request. | ||||
|  | ||||
| Client objects are stateful - they will retain cookie (and | ||||
| thus session) details for the lifetime of the Client instance. | ||||
| ``Client`` objects are stateful - they will retain cookie (and | ||||
| thus session) details for the lifetime of the ``Client`` instance. | ||||
|  | ||||
| This is not intended as a replacement for Twill,Selenium, or | ||||
| This is not intended as a replacement for Twill, Selenium, or | ||||
| other browser automation frameworks - it is here to allow | ||||
| testing against the contexts and templates produced by a view, | ||||
| rather than the HTML rendered to the end-user. | ||||
|   | ||||
| @@ -1,16 +1,16 @@ | ||||
| """ | ||||
| 38. User-registered management commands | ||||
|  | ||||
| The manage.py utility provides a number of useful commands for managing a | ||||
| The ``manage.py`` utility provides a number of useful commands for managing a | ||||
| Django project. If you want to add a utility command of your own, you can. | ||||
|  | ||||
| The user-defined command 'dance' is defined in the management/commands  | ||||
| subdirectory of this test application. It is a simple command that responds  | ||||
| The user-defined command ``dance`` is defined in the management/commands | ||||
| subdirectory of this test application. It is a simple command that responds | ||||
| with a printed message when invoked. | ||||
|  | ||||
| For more details on how to define your own manage.py commands, look at the | ||||
| django.core.management.commands directory. This directory contains the | ||||
| definitions for the base Django manage.py commands. | ||||
| For more details on how to define your own ``manage.py`` commands, look at the | ||||
| ``django.core.management.commands`` directory. This directory contains the | ||||
| definitions for the base Django ``manage.py`` commands. | ||||
| """ | ||||
|  | ||||
| __test__ = {'API_TESTS': """ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user