I have declared a manager to the following model, but after doing so, I can no longer use List.objects.get(). Anybody know why?
class List(models.Model):
title = models.CharField(max_length=20, unique=True)
archived = models.BooleanField()
archived_lists = ArchivedListManager()
active_lists = ActiveListManager()
And the managers:
class ArchivedListManager(models.Manager):
def get_query_set(self):
return super(ArchivedListManager, self).get_query_set().filter(archived=True)
class ActiveListManager(models.Manager):
def get_query_set(self):
return super(ActiveListManager, self).get_query_set().filter(archived=False)
The error is type object 'List' has no attribute 'objects'
As noted in the Django docs:
So as far as “why” goes, it’s to allow you to provide your own default manager.
The solution is simple, though: just add this
to your model class.