Hi all,

many of my models have a boolean field "is_active".

Now I'd like to implement a convenience method that automatically uses
this field when accessing my models.

What is the best way to implement something like
MyModel.objects.filter_active()?

One (quite non-elegant) way would be adding a method to the class
Manager in django.db.models.manager like this:

    def filter_active(self, *args, **kwargs):
        kwargs['is_active'] = kwargs.get('is_active', True)
        return self.get_query_set().filter(*args, **kwargs)

But that would mean changing django core files, which I really do not
like. I'd much prefer adding a method to my own model - but how?

Hoping for some clues...

Martin


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