pass a list to object_list

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class qs_list(object):
    """
    A semi-list-like object which includes the additional _clone and replaced count method of QuerySets. 
    This is necessary for passing a list to the object_list generic view, which usually expects
    a QuerySet.
    """
    def __init__(self, *args):
        self.l = list(*args)
    def __getattr__(self, *args):
        return self.l.__getattr__(*args)
    def __iter__(self, *args):
        return self.l.__iter__(*args)
    def __getitem__(self, *args):
        item = self.l.__getitem__(*args)
        if isinstance(item, list):
            return qs_list(item)
    def _clone(self):
        return self
    def count(self):
        return len(self.l)

Comments

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.