On Wed, 2007-07-04 at 19:15 +0000, cesco wrote:
> Hi,
> 
> in django we can chain multiple filter methods like:
> 
> MyModel.objects.filter(field1__exact=value1).filter(field2__exact=value2)
> 
> but I'd like to be able to chain custom filter methods defined by
> extending the models.Manager class.
> For example:
> 
> MyModel.objects.filter(field1__exact=value1).my_filter(field2)
> 
> In other words I'd like to be able to apply the filter directly to a
> queryset and not only to MyModel.objects.
> 
> Do you have any suggestion on how to accomplish that?

Sub-class the QuerySet class and have your model's manager return your
subclass as the result of get_query_set() rather than the current
QuerySet instance that is returned.

Look in django/db/models/manager.py for the default manager behaviour
and write something similar for get_query_set().

Regards,
Malcolm

-- 
Tolkien is hobbit-forming. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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