On Fri, 2007-05-18 at 23:50 +0200, Olivier Guilyardi wrote:
> Hi,
> 
> How can I know about the limiting parameters inside a custom manager method?
> 
> Example:
> 
> class MyManager(models.Manager):
>     def my_query(self):
>         # How can I find out about offset and length ?
>         cursor.execute("SELECT foo FROM bar LIMIT %d, %d", [offset, length])
> 
> class MyModel(models.Model)
>     foo = models.CharField(maxlength=200)
>     my_objects = MyManager()
> 
> # The following should result in offset=0 and length=5 above
> first_rows = MyModel.my_objects.my_query()[:5]
> 
> Is this possible?

Not really, no. Python will process the slice arguments ("[:5]") after
it has called my_query().

The way we work around this in QuerySet is to ensure that every QuerySet
method (with a few exceptions) returns another QuerySet and we implement
__getslice__ on the QuerySet class. You would need to emulate that
behaviour if you really wanted this.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to