I have the following ModelAdmin:
class EventAdmin(admin.ModelAdmin):
# ModelAdmin config
def queryset(self, request):
queryset = super(EventAdmin, self).queryset(request)
return queryset.exclude(date_end__lt=date.today())
admin.site.register(Event, EventAdmin)
Now I want to add a model to manage archived (older than today) events.
class EventArchiveAdmin(admin.ModelAdmin):
# ModelAdmin config
def queryset(self, request):
queryset = super(EventArchiveAdmin, self).queryset(request)
return queryset.filter(date_end__lt=date.today())
admin.site.register(Event, EventArchiveAdmin)
But if I try to do so I get AlreadyRegistered exception.
Why can't I implement another ModelAdmin with same Model and how can I get different admin views of the same model?
I know I can implement a custom list_filter
in my class but I'd like to keep things separated in different pages.
Use proxy models:
Now, you can register 2 models without override
ModelAdmin.queryset
method:You can read mode about proxy models and managers in the doc.
Also, use this:
As first argument
super()
take current class. See docNote: django has renamed
Manager.get_query_set
toManager.get_queryset
in django==1.7.