Friday, March 5, 2021

Re: How to hide/disable ModelAdmin

Seems I know the answer:

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

https://stackoverflow.com/questions/2431727/django-admin-hide-a-model
https://stackoverflow.com/questions/49293901/hide-model-from-main-admin-list-but-allow-creation-in-inline-editor
Dne čtvrtek 4. března 2021 v 21:22:41 UTC+1 uživatel zvo...@seznam.cz napsal:
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.
```

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/98a443b2-15f7-4172-bd8e-1635dc98f30an%40googlegroups.com.

No comments:

Post a Comment