1👍
✅
Entry.objects
is a manager, not a queryset. You put published
inside your custom queryset, so you need to do Entry.objects.all().published()
or Entry.objects.get_queryset().published()
You also aren’t implementing published
correctly. It should be more like:
class EntryQueryset(QuerySet):
def published(self):
return self.filter(status='published')
0👍
Your method published()
should be on the EntryManager class, there is no need to create a new QuerySet class (generally that is only when you want to dig deeper into how data is fetched from the database).
The correct solution would be:
class EntryManger(models.Manager):
def published(self):
print 'using right custom manager'
return self.filter(self.status == 'published')
You can delete the EntryQuerySet
class entirely.
- [Answer]-Adding 2 models inside a Admin Manager
- [Answer]-Invalid response of JSON data from Django QuerySet
- [Answer]-Django reg exp in urls.py
Source:stackexchange.com