On 11/3/05, eas <[EMAIL PROTECTED]> wrote:
> class Thing(meta.Model):
>     name = meta.CharField(maxlength=100)
>
> class Person(meta.Model):
>     zipcode = meta.CharField(blank=True, maxlength=5)
>     nickname = meta.CharField(maxlength=100)
>
> class Connection(meta.Model):
>     blog = meta.ForeignKey(Thing)
>     owner = meta.ForeignKey(Person, edit_inline=meta.TABULAR,
> core=False)
> [...]
> >>>things.get_list(connection__owner__zipcode__exact='98109') fails
> as does
> things.get_list(connection__pk=1) which gives the error "TypeError: got
> unexpected keyword argument 'connection__pk'"

things.get_list(connection__pk=1) isn't a valid use of the API. The
only dynamic parameter you can pass to things.get_list() would start
with "name" -- e.g. things.get_list(name__contains='foo').

To accomplish what you want to do, try this:

>>> connection_list =
connections.get_list(owner__zipcode__exact='98109',
select_related=True)

>>> things.get_list(id__in=[c.blog_id for c in connection_list])

This is two queries instead of one, of course. If you're concerned
with efficiency, you can write the SQL manually. See the example here:
http://www.djangoproject.com/documentation/models/custom_methods/

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Reply via email to