mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
magic-removal: Added unit tests to ensure related manager descriptors extend the default manager for a model.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2747 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5d7c1fe714
commit
2fb5a9b7fe
@ -30,6 +30,7 @@ class Book(models.Model):
|
|||||||
author = models.CharField(maxlength=30)
|
author = models.CharField(maxlength=30)
|
||||||
is_published = models.BooleanField()
|
is_published = models.BooleanField()
|
||||||
published_objects = PublishedBookManager()
|
published_objects = PublishedBookManager()
|
||||||
|
authors = models.ManyToManyField(Person, related_name='books')
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.title
|
return self.title
|
||||||
@ -58,6 +59,11 @@ API_TESTS = """
|
|||||||
>>> Person.objects.get_fun_people()
|
>>> Person.objects.get_fun_people()
|
||||||
[Bugs Bunny]
|
[Bugs Bunny]
|
||||||
|
|
||||||
|
# The RelatedManager used on the 'books' descriptor extends the default manager
|
||||||
|
>>> from modeltests.custom_managers.models import PublishedBookManager
|
||||||
|
>>> isinstance(p2.books, PublishedBookManager)
|
||||||
|
True
|
||||||
|
|
||||||
>>> b1 = Book(title='How to program', author='Rodney Dangerfield', is_published=True)
|
>>> b1 = Book(title='How to program', author='Rodney Dangerfield', is_published=True)
|
||||||
>>> b1.save()
|
>>> b1.save()
|
||||||
>>> b2 = Book(title='How to be smart', author='Albert Einstein', is_published=False)
|
>>> b2 = Book(title='How to be smart', author='Albert Einstein', is_published=False)
|
||||||
@ -70,6 +76,11 @@ Traceback (most recent call last):
|
|||||||
...
|
...
|
||||||
AttributeError: type object 'Book' has no attribute 'objects'
|
AttributeError: type object 'Book' has no attribute 'objects'
|
||||||
|
|
||||||
|
# The RelatedManager used on the 'authors' descriptor extends the default manager
|
||||||
|
>>> from modeltests.custom_managers.models import PersonManager
|
||||||
|
>>> isinstance(b2.authors, PersonManager)
|
||||||
|
True
|
||||||
|
|
||||||
>>> Book.published_objects.all()
|
>>> Book.published_objects.all()
|
||||||
[How to program]
|
[How to program]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user