I have django-admin-interface installed in my django app. I configured layout using this plugin and I would like to hide it from admin panel. My goal is to store basic settings in database. Is it possible?
I can't find any relations in my code to this plugin. There is only one place in my code (settings.py) where phrase admin_interface appears.
INSTALLED_APPS = [
'mainapp.apps.MainappConfig',
'admin_interface',
'colorfield',
'flat_responsive',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'smart_selects',
'activatable_model',
'bootstrap3',
'mainapp.apps.ConstanceConfig',
'constance.backends.database',
'kronos',
'ckeditor',
'django_admin_listfilter_dropdown',
]
Is is possible to hide this area in admin panel?
You can use unregister in your admin.py.
from django.contrib import admin
from admin_interface.models import Theme
admin.site.unregister(Theme)
Note:
If you have multiple apps and hence multiple admin.py, then adding this snippet in anyone of them will hide the app
Related
I have a installed an app called 'Login', who have a folder 'models' inside, with a custom_user model. The problem occurs when I tried to configure settings.py, specially auth_user_model.
in installed apps I have the following:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'project_app.login'
]
and below
AUTH_USER_MODEL = 'login.models.CustomUser'
But I have the following error: "Invalid model reference. String model references must be of the form 'app_label.ModelName'." I put the .models in AUTH_USER_MODEL, because I want to reference the app that the CustomUser is inside the folder "models" in Login.
Also, I tried with declare like this:
AUTH_USER_MODEL = 'login.CustomUser'
but the error is this: 'AUTH_USER_MODEL refers to model 'login.CustomUser' that has not been installed'
The issue is with the way that your app is installed - based on your AUTH_USER_MODEL, login should be the name of the app. It is acceptable to contain Django apps within folders for organisation purposes - however, your parent folder is project_app which from the name also appears to be an app. It's hard to say for certain what the issue is without knowing your project structure but I would expect changing your installed apps to just project_app and your AUTH_USER_MODEL to project_app.CustomerUser should work.
If your app name is "login", you can proceed as follows:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
#apps
'login.apps.LoginConfig']
I think the model in your login application is as follows:
class CustomUser(AbstractBaseUser):
#some fields for customuser
and in settings.py:
AUTH_USER_MODEL = 'user.CustomUser'
AUTH_USER_MODEL = 'app_name.ModelName'
I am trying to install the sites package and upon running makemigrations am receiving the error:
django.contrib.admin.sites.AlreadyRegistered: The model Site is
already registered in app 'sites'.
This is my admin.py:
from django.contrib import admin
# Register your models here.
from django.apps import apps
models = apps.get_models()
for model in models:
try:
admin.site.register(model)
except admin.sites.AlreadyRegistered:
pass
And here are my installed apps:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'webpage',
'django_user_agents',
'analytical',
'corsheaders',
'django.contrib.sites',
]
Any idea what might be causing this issue? Please let me know if there is information missing.
You are registering all models of all apps in your admin.py. You seem to be aware of the fact that some model may already be registered and use a try-except block to catch that. But the problem is that other packages don't know that you are doing this and obviously won't use try-except blocks. You get the error because you successfully register the model Site with the admin site but then when django.contrib.sites tries to register the same it fails since it is already registered.
One solution may to be order your INSTALLED_APPS better and your apps be last. Currently you have django.contrib.sites listed after many apps (even third party ones):
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', # Move it here
'webpage',
'django_user_agents',
'analytical',
'corsheaders',
]
Again this might cause errors if some other apps try to register their models. Instead of doing this brute force registering of all models consider registering the models for only your app inside it's admin.py:
from django.contrib import admin
# Register your models here.
from django.apps import apps
app_config = apps.get_app_config('your_app_name') # Replace your_app_name it is just a placeholder
models = app_config.get_models()
for model in models:
try:
admin.site.register(model)
except admin.sites.AlreadyRegistered:
pass
Your admin registered the models of sites app before sites app, the best solution is to skip the sites model in your admin so the admin in sites can register its models.
Tying to register my djano app in the settings section of my django project. but when i run the server i am getting an error in the terminal.
django.core.exceptions.ImproperlyConfigured: 'site1app.apps' does not contain a class 'Site1appConfig'. Choices are: 'Site1AppConfig'.
I dont know what's going wrong as i just added it to the list of installed apps in settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'site1app.apps.Site1appConfig',
]
This looks like a miss on the capitalization for your class
Change:
'site1app.apps.Site1appConfig'
To:
'site1app.apps.Site1AppConfig'
I want extend Application model of django oauth toolkit. They have given intsructions here link
But i am not getting how to do it. I have created one app inside apps folder and inside models i have added the following code.
from django.db import models
from oauth2_provider.models import AbstractApplication
class MyApplication(AbstractApplication):
logo = models.ImageField()
agree = models.BooleanField()
Resgitered the app inside installed_apps as 'apps.oauth2', and added the following line:
OAUTH2_PROVIDER_APPLICATION_MODEL='apps.OAuth2'
But it giving me error
LookupError: No installed app with label 'apps'.
Installed Apps [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'apps.commons',
'apps.company',
'apps.oauth2',
]
According this manual link model in OAUTH2_PROVIDER_APPLICATION_MODEL should be class name not app
I have a trouble with plugging recently created app called pages into a django project.
My pages apps.py
from django.apps import AppConfig
class PagesConfig(AppConfig):
name = 'pages'
My settings.py, installed apps:
INSTALLED_APPS = [
'pages.apps.PagesConfig' # pages.apps.pages fails too
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
ImportError: No module named 'pages.apps.PagesConfigdjango';
'pages.apps' is not a package
Does anyonw knows what is wrong there? I did everything according the docs, but django still cannot to plug my app. Any insights appreciated.
You are missing a comma after your entry.
'pages.apps.PagesConfig',