Reputation: 41785
I'd like my model has multiple list view
endpoints in django admin.
For instance, I'd like to view all the blogs with more than 5 comments
all the blogs that has been shared
How do you make multiple endpoints in django admin? (basically multiple querysets for one model class)
Sure I can use something like https://github.com/jsocol/django-adminplus but It would take many hours to create the templates...
Upvotes: 1
Views: 378
Reputation: 45595
Create several proxy models:
class SharedBlog(Blog):
class Meta:
proxy = True
verbose_name = 'shared blog'
And override the get_queryset()
method of the ModelAdmin
:
class SharedBlogAdmin(admin.ModelAdmin):
def get_queryset(self, request):
qs = super(SharedBlogAdmin, self).get_queryset(request)
return qs.filter(shared=True)
admin.site.register(SharedBlog, SharedBlogAdmin)
Upvotes: 4