Commit 02fcfe62 authored by Adrian Holovaty's avatar Adrian Holovaty
Browse files

Cleaned up numbering with model unit tests

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3031 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent a8461551
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
"""
XXX. Callable defaults
31. Callable defaults

???
You can pass callable objects as the ``default`` parameter to a field. When
the object is created without an explicit value passed in, Django will call
the method to determine the default value.

This example uses ``datetime.datetime.now`` as the default for the ``pub_date``
field.
"""

from django.db import models
@@ -11,7 +16,7 @@ class Article(models.Model):
    headline = models.CharField(maxlength=100, default='Default headline')
    pub_date = models.DateTimeField(default=datetime.now)

    def __repr__(self):
    def __str__(self):
        return self.headline

API_TESTS = """
@@ -43,6 +48,4 @@ API_TESTS = """
>>> d = now - a.pub_date
>>> d.seconds < 5
True


"""
+5 −5
Original line number Diff line number Diff line
"""
27. Many-to-many and many-to-one relationships to the same table

This is a response to bug #1535
28. Many-to-many and many-to-one relationships to the same table

Make sure to set ``related_name`` if you use relationships to the same table.
"""

from django.db import models
@@ -14,8 +13,9 @@ class Issue(models.Model):
    num = models.IntegerField()
    cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
    client = models.ForeignKey(User, related_name='test_issue_client')
    def __repr__(self):
        return "<Issue %d>" % (self.num,)

    def __str__(self):
        return str(self.num)

    class Meta:
        ordering = ('num',)
+15 −15
Original line number Diff line number Diff line
"""
26. Many-to-many relationships between the same two tables
27. 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 relationshiup - if I am your friend, you are my friend.
+1 −1
Original line number Diff line number Diff line
"""
25. Default manipulators
26. Default manipulators

Each model gets an AddManipulator and ChangeManipulator by default.
"""
+1 −1
Original line number Diff line number Diff line
"""
28. Object pagination
29. Object pagination

Django provides a framework for paginating a list of objects in a few lines
of code. This is often useful for dividing search results or long lists of
Loading