121👍
In an admin.py you know will definitely be loaded, try:
admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.unregister(Site)
10👍
In addition to the above double check your ordering of “INSTALLED_APPS” in “settings.py”
INSTALLED_APPS = [
# django apps first
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# custom apps below
'my_app'
]
Otherwise it will cause an error. See here: Issue with Django admin registering an inline user profile admin
- [Django]-Django can' t load Module 'debug_toolbar': No module named 'debug_toolbar'
- [Django]-Duplicate column name
- [Django]-How do I create a slug in Django?
8👍
To get rid of Users and Groups I had to do in admin.py:
from django.contrib import admin
# Need to import this since auth models get registered on import.
import django.contrib.auth.admin
import django.contrib.auth.models
from django.contrib import auth
admin.site.unregister(auth.models.User)
admin.site.unregister(auth.models.Group)
- [Django]-How to get form fields' id in Django
- [Django]-Visual Editor for Django Templates?
- [Django]-Bulk create model objects in django
3👍
Loop through all apps, and unregister any models they have registered.
from django.apps import apps
# De-register all models from other apps
for app_config in apps.get_app_configs():
for model in app_config.get_models():
if admin.site.is_registered(model):
admin.site.unregister(model)
# Register only those models you want
...
- [Django]-Django. A good tutorial for Class Based Views
- [Django]-How to send a correct authorization header for basic authentication
- [Django]-Unable to find a locale path to store translations for file __init__.py
1👍
If you got:
django.contrib.admin.sites.NotRegistered: The model Group is not
registered
Then make sure that your INSTALLED_APPS in proper order like this:
enter code hereINSTALLED_APPS = (
# [1] Django apps
'django.contrib.auth',
...
# [2] your custom apps
'anyproject.anytuff',
)
- [Django]-Cron and virtualenv
- [Django]-How do I create a slug in Django?
- [Django]-Pypi see older versions of package
0👍
from django.apps import apps
for model in apps.get_models():
if model.__name__ and admin.site.is_registered(model):
admin.site.unregister(model)
this will unregister all models depending upon the position of app where this code is placed and it’s order inside INSTALLED_APPS so make sure the apps you want in your admin are placed after the app in which this code resides.
For Example: if this code is placed inside users app, it will unregister all models before users and all models after users can be registered.
- [Django]-Django dump data for a single model?
- [Django]-How to do SELECT MAX in Django?
- [Django]-List_display – boolean icons for methods