On 3/9/07, David Danier <[EMAIL PROTECTED]> wrote:
>
> I don't see the real advantage over:
> --------8<---------------------------------------------
> from foo.accounts.models import User
> [...]
> models.ForeignKey(User)
> --------------------------------------------->8--------
>
Check out the ticket.  It provides an example where models are
mutually referential, and will not allow the standard Python import
methodology.  The brief example in my orginal post was just to express
the notation.  The actual ticket goes deeper into the value of the
change.

> Am I right, that this helps when you don't know (or don't want to) where
> the application is  stored or the application might be exchangeable?
This is a potential use case, but is not the primary intended purpose.
 Again, please check out the ticket for an example.

> I like this idea, but is there a real advantage over using this?
> (except for looking nicer)
> --------8<---------------------------------------------
> from django.db.models.loading import get_model
> [...]
> models.ForeignKey(get_model('account', 'User'))
> --------------------------------------------->8--------

In the mutualy referential case, yes... there is an added advantage of
using the patch.  Because the objects are not fully defined, Python
won't know how to handle the situation using your proposal.

Consider the last examples in the ticket.... if you try to use
get_model in both cases, the model used first will then try to use
get_model to resolve the second, which will call get_model to resolve
the first which hasn't been fully defined yet, and must then call
get_model on the second. (confusing, no?)  The result is an infinte
loop.

Whichever of our fearless leaders wrote the current code for resolving
string-based relationships came up with a handy deferral mechanism
that bypasses the typical (serial) loading process.  Just using
get_model by itself doesn't solve the recursive relationship problem,
but the deferral approach does.

I hope this clears things up.  If not, please let me know.

  - Ben

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to