On Tue, Apr 14, 2009 at 6:00 PM, gordyt <gor...@gmail.com> wrote:

>
> I think I've tracked down the problem.  Here is a bit of code from
> django.db.models.fields.related.py:
>
>    def get_db_prep_lookup(self, lookup_type, value):
>        # If we are doing a lookup on a Related Field, we must be
>        # comparing object instances. The value should be the PK of
> value,
>        # not value itself.
>        def pk_trace(value):
>            # Value may be a primary key, or an object held in a
> relation.
>            # If it is an object, then we need to get the primary key
> value for
>            # that object. In certain conditions (especially one-to-
> one relations),
>            # the primary key may itself be an object - so we need to
> keep drilling
>            # down until we hit a value that can be used for a
> comparison.
>            v, field = value, None
>            try:
>                while True:
>                    v, field = getattr(v, v._meta.pk.name), v._meta.pk
>
>            except AttributeError:
>                pass
>            if field:
>                if lookup_type in ('range', 'in'):
>                    v = [v]
>                v = field.get_db_prep_lookup(lookup_type, v)
>                if isinstance(v, list):
>                    v = v[0]
>            # BEGIN (got)
>            else:
>                field = self.rel.get_related_field()
>                if field:
>                    v = field.get_db_prep_lookup(lookup_type, v)
>            # END (got)
>            return v
>
> I added the part between BEGIN and END.
>
> The problem was that, for the child model in multi-table inheritance,
> its primary key in the database was being created by django as a
> OneToOneField (which is correct, of course), and it was creating the
> column using the proper type and everything, but you can see that
> without the little part that I added, the value was not being properly
> prepared for a lookup.
>
> --gordy
> >
>
Take a look at: http://code.djangoproject.com/ticket/10785

Alex
-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

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

Reply via email to