Answer the question
In order to leave comments, you need to log in
How to display article archive?
admin.py:
class ArticleAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'author', 'status', 'sub_category', 'show_on_main')
list_editable = ('status', 'show_on_main')
inlines = (ParagraphInline,)
list_per_page = 20
actions = ['delete_selected']
def get_queryset(self, request):
if not request.user.is_superuser and not request.user.groups.filter(name='Moderation'):
return Article.objects.filter(author=request.user, archive=False)
return Article.objects.filter(archive=False)
def delete_model(self, request, obj):
obj.archive = True
obj.save()
def delete_selected(self, request, obj):
for item in obj:
item.archive = True
item.save()
class ArchiveAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'author', 'status', 'sub_category', 'show_on_main')
inlines = (ParagraphInline,)
list_per_page = 20
def get_queryset(self, request):
return Article.objects.filter(archive=True)
admin.site.register(Article, ArticleAdmin)
admin.site.register(Article, ArchiveAdmin)
django.contrib.admin.sites.AlreadyRegistered: The model Article is already registered
Answer the question
In order to leave comments, you need to log in
Unfortunately, more than 1 admin class cannot be registered for the same model.
There is a variant with a proxy model, look here . There is even a similar topic - publications.
Just in case, there is a second option.
If you set up two admin sites in Django, for example, one for users with a limited set of models, and the second for the admin with all models and / or with archive records.
It can be seen from the question that the architecture of the project just involves separating work with models (why are the archived articles taken out separately for some reason?)
Then you can not create proxies for each "archived" model (if there are a lot of them), but it is easy to register the same model in different admins:
# для всех
admin.site.register(Article, ArticleAdmin)
# для админа и модераторов архива
archive.register(Article, ArchiveAdmin)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question