~ubuntu-branches/ubuntu/natty/python-django/natty-security

« back to all changes in this revision

Viewing changes to tests/modeltests/custom_managers/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2011-02-17 13:34:07 UTC
  • mfrom: (1.1.13 upstream) (4.4.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110217133407-rwr88elhhq6j7ba0
Tags: 1.2.5-1ubuntu1
* Merge from Debian for security fixes (LP: #719031). Remaining changes:
  - debian/control: don't Build-Depends on locales-all, which doesn't exist
    in natty
* Drop the following patches, now included upstream:
  - debian/patches/07_security_admin_infoleak.diff
  - debian/patches/08_security_pasword_reset_dos.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
 
58
58
    def __unicode__(self):
59
59
        return self.name
60
 
 
61
 
__test__ = {'API_TESTS':"""
62
 
>>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True)
63
 
>>> p1.save()
64
 
>>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False)
65
 
>>> p2.save()
66
 
>>> Person.objects.get_fun_people()
67
 
[<Person: Bugs Bunny>]
68
 
 
69
 
# The RelatedManager used on the 'books' descriptor extends the default manager
70
 
>>> from modeltests.custom_managers.models import PublishedBookManager
71
 
>>> isinstance(p2.books, PublishedBookManager)
72
 
True
73
 
 
74
 
>>> b1 = Book(title='How to program', author='Rodney Dangerfield', is_published=True)
75
 
>>> b1.save()
76
 
>>> b2 = Book(title='How to be smart', author='Albert Einstein', is_published=False)
77
 
>>> b2.save()
78
 
 
79
 
# The default manager, "objects", doesn't exist,
80
 
# because a custom one was provided.
81
 
>>> Book.objects
82
 
Traceback (most recent call last):
83
 
    ...
84
 
AttributeError: type object 'Book' has no attribute 'objects'
85
 
 
86
 
# The RelatedManager used on the 'authors' descriptor extends the default manager
87
 
>>> from modeltests.custom_managers.models import PersonManager
88
 
>>> isinstance(b2.authors, PersonManager)
89
 
True
90
 
 
91
 
>>> Book.published_objects.all()
92
 
[<Book: How to program>]
93
 
 
94
 
>>> c1 = Car(name='Corvette', mileage=21, top_speed=180)
95
 
>>> c1.save()
96
 
>>> c2 = Car(name='Neon', mileage=31, top_speed=100)
97
 
>>> c2.save()
98
 
>>> Car.cars.order_by('name')
99
 
[<Car: Corvette>, <Car: Neon>]
100
 
>>> Car.fast_cars.all()
101
 
[<Car: Corvette>]
102
 
 
103
 
# Each model class gets a "_default_manager" attribute, which is a reference
104
 
# to the first manager defined in the class. In this case, it's "cars".
105
 
>>> Car._default_manager.order_by('name')
106
 
[<Car: Corvette>, <Car: Neon>]
107
 
"""}