How to hide/disable ModelAdmin

182 views
Skip to first unread message

zvo...@seznam.cz

unread,
Mar 4, 2021, 3:22:41 PM3/4/21
to Django users
I want use Django 2+ autocomplete_fields.
Adding them into (source) ModelAdmin will give lot of errors (see bellow).
So I must add a (target) ModelAdmin with search_fields=...

After that everything works.
However I don't want to have such new ModelAdmin's visible/accessible.
I have data of their models already much better accessible in Inlines.

Is there a way how to give search_fields=.. and not show the new ModelAdmin?

Thank you.

```
ERRORS:
<class 'apps.rap.admin.PartCodeInline'>: (admin.E039) An admin for model "PartVariant" has to be registered to be referenced by PartCodeInline.autocomplete_fields.
<class 'apps.rap.admin.PartCodeInline'>: (admin.E040) PartCodeTypeAdmin must define "search_fields", because it's referenced by PartCodeInline.autocomplete_fields.
<class 'apps.rap.admin.PartSizeInline'>: (admin.E039) An admin for model "Size" has to be registered to be referenced by PartSizeInline.autocomplete_fields.
<class 'apps.rap.admin.PartSubGroupInline'>: (admin.E039) An admin for model "Size" has to be registered to be referenced by PartSubGroupInline.autocomplete_fields.
```

zvo...@seznam.cz

unread,
Mar 5, 2021, 5:37:00 AM3/5/21
to Django users
Seems I know the answer:

class HiddenAdmin(admin.ModelAdmin):
    has_module_permission = lambda self, req: False

Dne čtvrtek 4. března 2021 v 21:22:41 UTC+1 uživatel zvo...@seznam.cz napsal:
Reply all
Reply to author
Forward
0 new messages