Malcolm Tredinnick wrote: > On Fri, 2007-05-18 at 23:50 +0200, Olivier Guilyardi wrote: >> >> 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().
Okay, so I suppose a workaround is to pass offset and length as arguments to 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. I see. I would need to return an object that implements __getslice__, and perform my SQL query in this object. I suppose I may also try to extend the QuerySet class to add my own method. But this might get rather complex AFAICS in db.models.query. Thanks for the tips -- Olivier --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---