I've been trying to unregister the admin for sites in django by doing the following:
from django.contrib.sites.models import Site
admin.site.unregister(Site)
However this gives me an error stating that "Site" is not registered (even though it showed up in admin before).
If I try doing the following I get no errors but "Site" stays in the admin:
from django.contrib.sites.models import Site
admin.site.register(Site)
admin.site.unregister(Site)
I need the sites app and cannot take it out of INSTALLED_APPS in settings. However the admin for it is utterly useless to me. Any ideas on what I am doing wrong here?
Thanks!
You can unregister default models in admin.py of your app by using unregister .
Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .
The Django admin is an automatically-generated user interface for Django models. The register function is used to add models to the Django admin so that data for those models can be created, deleted, updated and queried through the user interface.
You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category , the admin displays Categorys , but by adding the Meta class, we can change it to Categories . Literally saved my life!
The order of your INSTALLED_APPS
setting is important.
When Django starts it will import the applications in INSTALLED_APPS
in the order they are defined (https://docs.djangoproject.com/en/1.11/ref/applications/#how-applications-are-loaded). In your example above you were unregistering Site
before Django had the chance to register is it.
There isn't much you can do in terms of troubleshooting except for reading the logs very carefully. After staring at them for a while you either become one with Django and understand it all, or you come here like the rest of us ;-)
My INSTALLED_APPS
usually start with the django.contrib
apps, then any 3rd-party applications, then my apps at the bottom. I only change this if I have a very good reason to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With