from django.contrib.sites.managers import CurrentSiteManager from django.db.models import Manager from django.db.models.manager import ManagerDescriptor from django.contrib.contenttypes.models import ContentType from django.db.models import Q from flag.models import FlaggedContent class GenericManager(Manager): def get_query_set(self): f=~Q(id__in=getapprovedids(self.model)) return super(GenericManager, self).get_query_set().filter(f) class SiteManager(CurrentSiteManager): def get_query_set(self): f=~Q(id__in=getapprovedids(self.model)) return super(SiteManager, self).get_query_set().filter(f) def getapprovedids(model): ct=ContentType.objects.get_for_model(model) statusfilter= Q(status=4) | Q(status=5) ids=FlaggedContent.objects.filter(Q(content_type=ct), statusfilter).values_list('object_id') return map(lambda x: x[0],ids) def register(model): for key in model.__dict__: if(type(model.__dict__[key])==ManagerDescriptor): if type(model.__dict__[key].manager)==Manager: GenericManager().contribute_to_class(model,key) else: SiteManager().contribute_to_class(model,key) """ Usage Example: Put the above code in your django-flag.__init__.py . Wherever applicable, state the following code: from flag import register from myapp.models import mymodel register(mymodel) """