58
58
def __unicode__(self):
61
__test__ = {'API_TESTS':"""
62
>>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True)
64
>>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False)
66
>>> Person.objects.get_fun_people()
67
[<Person: Bugs Bunny>]
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)
74
>>> b1 = Book(title='How to program', author='Rodney Dangerfield', is_published=True)
76
>>> b2 = Book(title='How to be smart', author='Albert Einstein', is_published=False)
79
# The default manager, "objects", doesn't exist,
80
# because a custom one was provided.
82
Traceback (most recent call last):
84
AttributeError: type object 'Book' has no attribute 'objects'
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)
91
>>> Book.published_objects.all()
92
[<Book: How to program>]
94
>>> c1 = Car(name='Corvette', mileage=21, top_speed=180)
96
>>> c2 = Car(name='Neon', mileage=31, top_speed=100)
98
>>> Car.cars.order_by('name')
99
[<Car: Corvette>, <Car: Neon>]
100
>>> Car.fast_cars.all()
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>]