#2684: [patch] Backwards relations (ie. xxx_set) across different apps needs
voodoo magic to work
------------------------------+---------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: russellm
Type: defect | Status: assigned
Priority: normal | Milestone:
Component: Core framework | Version: SVN
Severity: normal | Resolution:
Keywords: |
------------------------------+---------------------------------------------
Comment (by russellm):
To clarify the exact problem; If you have a model A with a ForiegnKey/M2M
relation on model B, and your code is:
{{{
from test.project.models import B
objs = B.objects.all()
}}}
the members of ``objs`` don't have their related descriptors (e.g.,
b.a_set) instantiated. This is because the related models are never
imported, so the ``contribute_to_class`` methods for the related classes
are never called.
A single call to ``B.objects.get()``, ``B.objects.filter()``, or just
about anything else that interacts with fields will call the
``_meta.get_all_related_objects()`` and
``_meta.get_all_related_many_to_many_objects()`` methods to be called,
which causes these methods to fill their caches, which causes the related
models to be imported, and the related descriptors to be created.
Simple workaround, demonstrated in the patch - force the creation of an
object instance to cause the meta class instance to populate its caches.
--
Ticket URL: <http://code.djangoproject.com/ticket/2684>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---