def objects_for_user(self, user, qs=None, xmin__lte=None):
        qs = self.get_queryset(qs)
        user_rels = self.user_rel
        if user_rels:
            if user is None:
                return qs.none()  # no user but we need one: return no objects.
            if isinstance(user_rels, basestring):
                user_rels = [user_rels]
            user_filter = None
            # Django supports model._meta -> pylint: disable=W0212
            meta = self.model._meta
            for user_rel in user_rels:
                name, rel = (user_rel.split('__', 1) + [None])[:2]
                field = meta.pk if name == 'pk' else meta.get_field(name)
                # generate `filter_obj` (instance of django.db.models.Q)
                if field.related_model is not None:
                    # user_rel spans a join - ensure efficient SQL is generated
                    # such as `...WHERE foo_id IN (SELECT foo.id FROM ...)`
                    # rather than creating an explosion of INNER JOINS.
                    filter_obj = Q(**{
                        '%s__in' % name: field.related_model.objects.filter(
                            **{rel or 'pk': user}
                        ).values('pk'),
                    })
                else:
                    # user rel is a local field -> no joins to avoid.
                    filter_obj = Q(**{str(user_rel): user})
                # merge `filter_obj` into `user_filter`
                if user_filter is None:
                    user_filter = filter_obj
                else:
                    user_filter |= filter_obj
            qs = qs.filter(user_filter).distinct()
        if xmin__lte is not None:
            qs = qs.extra(
                where=["'xmin' <= %s"],
                params=[xmin__lte],
            )
        return qs
Redirect to an object's page based on a content-type ID and an object ID.
dataset/ETHPy150Open django-ddp/django-ddp/dddp/api.py/Collection.objects_for_user--crossover with--dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Django-1.6.10/django/contrib/contenttypes/views.py/shortcut