Re: Problem with query over relationships and the FOO_set Manager

2007-06-25 Thread ilDave

I tried your second solution and it works fine!

Thanks!



On Jun 25, 4:51 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > d = Details.objects.filter(creation_date__gte=datetime.date(2007, 06,
> > 01))
> > d = d.header_set.filter(code__exact='123', author__exact='dave')
>
> > but I get an
> > AttributeError: 'QuerySet' object has no attribute 'header_set'
>
> The results (which you store in "d") are a QuerySet which is a
> collection of Details.  Each Detail within that set has a
> header_set property.  Thus it would make sense to do something like
>
>for thing in d:
>  for header in thing.header_set:
>do_something(header)
>
> Or, if you want the headers, ask for them, not the details:
>
>since = datetime.date(2007,6,1)
>headers = Headers.objects.filter(
>  code='123',
>  author='dave',
>  header__creation_date__gte=since # (*)
>  )
>for header in headers:
>  do_something(header)
>
> The line marked with (*) may be what you're looking for.
>
> -tim


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem with query over relationships and the FOO_set Manager

2007-06-25 Thread Tim Chase

Whoops...though I hate responding to my own post, I got things 
backwards somehow (swapping details and headers).  Your Details 
have the header attribute so you want

since = datetime.date(2007,6,1)
details = Details.objects.filter(
  code='123',
  author='dave',
  header__creation_date__gte=since
  )
for detail in details:
  do_something(detail)


-tim




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem with query over relationships and the FOO_set Manager

2007-06-25 Thread James Bennett

On 6/25/07, ilDave <[EMAIL PROTECTED]> wrote:
> So, I looked in the documentation and I found the 'FOO_set' Manager,
> and I tried something like this:
>
> d = Details.objects.filter(creation_date__gte=datetime.date(2007, 06,
> 01))
> d = d.header_set.filter(code__exact='123', author__exact='dave')
>
> but I get an
> AttributeError: 'QuerySet' object has no attribute 'header_set'

The ForeignKey is on Detail, pointing at Header, which means that each
Detail has only one Header -- hence there is no "header_set" on a
Detail object.

What you probably want instead is

Detail.objects.filter(created_date__gte=datetime.date(2007, 6, 1),
header__code__exact='123', header__author__exact='dave')

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Problem with query over relationships and the FOO_set Manager

2007-06-25 Thread Tim Chase

> d = Details.objects.filter(creation_date__gte=datetime.date(2007, 06,
> 01))
> d = d.header_set.filter(code__exact='123', author__exact='dave')
> 
> but I get an
> AttributeError: 'QuerySet' object has no attribute 'header_set'

The results (which you store in "d") are a QuerySet which is a 
collection of Details.  Each Detail within that set has a 
header_set property.  Thus it would make sense to do something like

   for thing in d:
 for header in thing.header_set:
   do_something(header)

Or, if you want the headers, ask for them, not the details:

   since = datetime.date(2007,6,1)
   headers = Headers.objects.filter(
 code='123',
 author='dave',
 header__creation_date__gte=since # (*)
 )
   for header in headers:
 do_something(header)


The line marked with (*) may be what you're looking for.

-tim





--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---