Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model Manager queryset not filtering

I have a proxy model whose queryset is a subset of its parent. However, when I call it, the parent's objects are returned instead.

Model Manager:

class NewRequestsManager(models.Manager):        
    def get_queryset(self):
        return super(NewRequestsManager, self).get_queryset().filter(is_scoped=0)

Proxy Model:

class NewRequests(Engagement):
    objects = NewRequestsManager()

    class Meta:
        proxy = True
        app_label = 'myapp'
        verbose_name = 'New Request'

View:

def list(request):
    new_requests = NewRequests.objects.all()
    c = RequestContext(request, {
            'cl': new_requests,
    })
    t = loader.get_template('queue.html')
    return HttpResponse(t.render(c))

Any help is much appreciated. I'm not exactly sure what I'm missing here.

like image 423
chirinosky Avatar asked Mar 17 '13 05:03

chirinosky


2 Answers

Probably just a typo: get_queryset should be get_query_set, so you aren't overriding anything.

class NewRequestsManager(models.Manager):        
    def get_query_set(self):
        return super(NewRequestsManager, self).get_query_set().filter(is_scoped=0)
like image 185
Ric Avatar answered Sep 19 '22 01:09

Ric


Not a typo: dev documentation uses get_queryset whereas 1.5 documentation uses get_query_set I suppose there has been a recent change in dev version.

like image 38
Visgean Skeloru Avatar answered Sep 18 '22 01:09

Visgean Skeloru