from django.http import Http404
from django.db.models.manager import Manager

# Identical to get_list_or_404 
#  but returns a queryset for use in generic views
def get_queryset_or_404(klass, *args, **kwargs):
    if isinstance(klass, Manager):
        manager = klass
    else:
        manager = klass._default_manager
    queryset = manager.filter(*args, **kwargs)
    if not queryset:
        raise Http404('No %s matches the given query.' %
                        manager.model._meta.object_name)
    return queryset