I have an app called article
. I want to hide articles with hidden = True
. All hidden articles should not be findable except for admins.
I'm using a custom manager and I'm using a custom Modeladmin.
my custom modeladmin:
class ArticleAdmin(admin.ModelAdmin):
def get_queryset(self, request):
qs = super().get_queryset(request)
if request.user.is_superuser:
return qs
return qs.filter(hidden=False)
my custom manager:
class ArticleManager(models.Manager):
def get_queryset(self):
qs = super().get_queryset()
return qs.filter(hidden=False)
I want to get all articles with hidden = False
when I use Article.objects.all()
and when I'm in the admin panel I also want to get articles with hidden = True
.
Admin panel -> All articles
Article.objects.all() -> All articles with hidden = False
What's working:
When I use Article.objects.all() I get all articles with hidden = False
What's not working:
When I'm on the admin panel I don't see any articles with hidden = True
.
Only in the admin panel articles with hidden = True
should be visible. In Sitemaps, Querysets ... they shouldnt be returned.