On 1/25/06, Jason Davies <[EMAIL PROTECTED]> wrote:
>
>
> Joseph Kocherhans wrote:
>
> > At any rate, Managers and ManyToMany/OneToMany attributes do extremely
> > similar things, and I think they could share an api and maybe even
> > share most implementation. If managers behaved like object attributes,
> > this is what I'm worried about:
> >
> > MyModel.objects.filter(creator__exact=5)
> > for obj in MyModel.objects:
> >     print obj
>
> I was under the impression that you'd do something like:
>
> for obj in MyModel.objects.filter(creator__exact=5):
>     print obj

If this were the case then it would be impossible to combine filter
and order_by, at least in this way:

MyModel.objects.filter(creator__exact=5)
MyModel.objects.order_by('status')
for obj in MyModel.objects:
    print obj

For that code it seems like MyModel.objects should be a lazy
collection containing objects with creator=5 and ordered by status,
but in this case you would get an error because MyModel.objects
wouldn't support iteration.

If MyModel.objects (rather than MyModel.objects.filter()) instantiated
and returned a lazy collection, something like this should work as
expected:

for obj in MyModel.objects.filter(creator__exact=5).order_by('status'):
    print obj

Or this:

myobjects = MyModel.objects
myobjects.filter(creator__exact=5)
myobjects.order_by('status')
for obj in myobjects:
    print obj

Also, the current proposal doesn't apply to manipulators, just fields.
For the above you would still use managers like this:

MyModel.object.get_list(creator__exact=5, order_by=('status'))

Joseph

Reply via email to