5

I want to completely hide a model from a third-party module (otherapp) in admin site.

I put admin.site.unregister(ModelToHide) in one of my apps' admin (myapp), but it causes NotRegistered error on every page. The problem is that myapp.admin is loaded before otherapp.admin.

I tried to change the order INSTALLED_APPS so that otherapp comes before myapp, but it did not help, Django loads them in reverse order. I read in one of the SO comments that order of INSTALLED_APPS does not matter, as per Django book.

Actually, I created this question just to share the way I made it work for me, because it took some time to figure out the solution. Hope this helps someone.

1 Answer 1

5

There are two options:

  1. Put admin.site.unregister(ModelToHide) just after admin.autodiscover() in urls.py so that it runs after all models have been registered.
  2. Add an import to myapp.admin: import otherapp.admin so that it's loaded first.

Inspired by 1 and 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.