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.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With