mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #7904: added support for a "use_for_related_fields" property on managers. If True, the manager will be used for related object lookups instead of the "bare" QuerySet introduced bu [8107]. Patch from Justin Bronn.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8212 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -26,7 +26,7 @@ __test__ = {'API_TESTS':"""
|
||||
>>> private_source = Source.objects.create(is_public=False)
|
||||
>>> private_item = Item.objects.create(source=private_source)
|
||||
|
||||
Only one source is available via all() due to the custom default manager.
|
||||
# Only one source is available via all() due to the custom default manager.
|
||||
|
||||
>>> Source.objects.all()
|
||||
[<Source: Source object>]
|
||||
@@ -34,10 +34,21 @@ Only one source is available via all() due to the custom default manager.
|
||||
>>> public_item.source
|
||||
<Source: Source object>
|
||||
|
||||
Make sure that an item can still access its related source even if the default
|
||||
manager doesn't normally allow it.
|
||||
# Make sure that an item can still access its related source even if the default
|
||||
# manager doesn't normally allow it.
|
||||
|
||||
>>> private_item.source
|
||||
<Source: Source object>
|
||||
|
||||
# If the manager is marked "use_for_related_fields", it'll get used instead
|
||||
# of the "bare" queryset. Usually you'd define this as a property on the class,
|
||||
# but this approximates that in a way that's easier in tests.
|
||||
|
||||
>>> Source.objects.use_for_related_fields = True
|
||||
>>> private_item = Item.objects.get(pk=private_item.pk)
|
||||
>>> private_item.source
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
DoesNotExist: Source matching query does not exist.
|
||||
|
||||
"""}
|
||||
|
||||
Reference in New Issue
Block a user