using django grappelli dashboard with dotcloud - django

I'm trying to set up admin with grappelli on dotcloud services. I've got that all up and running fine however when I try and add a custom dashboard to the equation, I get errors stating:
ImportError at /admin/
No module named dashboard
However I have installed the django-grappelli as required and it is working without dashboard. All the requisites for dashboard should be there.
INSTALLED_APPS = (
'grappelli.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
GRAPPELLI_INDEX_DASHBOARD = 'www.dashboard.CustomIndexDashboard'

We might need a little bit more context here. But I would first look at the following in your Django settings:
Check INSTALLED_APPS and make sure that you specify grappelli.dashboard and not just dashboard.
Check GRAPPELLI_INDEX_DASHBOARD and make sure that you specify the full path to your custom dashboard module; e.g. if the class is MyDashboard in the dashboard.py file in your myapp directory, it should be myapp.dashboard.MyDashboard.

It's a little easier to solve than I first thought.
I basically just added the files for grappelli to the project rather than depending on dotcloud to install the dependencies.
Now it works fine.

Related

Pyforms web sample now working, only django's default site showing up

I'm trying to follow along with the example shown here: https://pyforms-web.readthedocs.io/en/v4/getting-started/first-app.html to get the first app running.
The Directory Structure of the default Django app looks like that.
I added the code as in the example, ran migrate and opened the brower, but only the default Django page shows up.
My site_crawl.py looks like this:
from pyforms.basewidget import BaseWidget
from confapp import conf
class SiteCrawlApp(BaseWidget):
UID = 'site-crawl-app'
TITLE = 'Site crawl'
LAYOUT_POSITION = conf.ORQUESTRA_HOME
ORQUESTRA_MENU = 'left'
ORQUESTRA_MENU_ICON = 'browser'
ORQUESTRA_MENU_ORDER = 0
The settings.py looks like:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'project',
]
Those are the only changes I made to the default structure created when I ran django-admin startproject project also ran python manage.py migrate before starting the web server with python manage.py runserver.
I'm using Python 3.6.0, Django 2.1.7 and Pyforms v4.
Can somebody help me figure out what I'm doing wrong? Thanks!

Field defines a relation with model 'MODEL', which is either not installed, or is abstract

Using custom user model in Django is like living in hell for me. After spending endless hours trying to get it done, now I face new problem: once I add some other app that depends on my custom user model I see this:
for example once I add 'django.contrib.admin', I see the error
admin.LogEntry.user: (fields.E300) Field defines a relation with model 'main.Usr', which is either not installed, or is abstract.
admin.LogEntry.user: (fields.E307) The field admin.LogEntry.user was declared with a lazy reference to 'main.usr', but app 'main' doesn't provide model 'usr'.
my settings is like
AUTH_USER_MODEL = 'main.Usr'
INSTALLED_APPS = [
'django.contrib.auth',
'main', # my app
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'debug_toolbar',
'django.contrib.postgres',
]
I had to suppress these system checks in order for django to load.
I put this in my settings.py
SILENCED_SYSTEM_CHECKS = ['fields.E300', 'fields.E307']
I don't recommend to enable this line unless you really know that the tables of the designated models really exist in the database.

RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS

I am building an application with Django Rest Framework and AngularJs. I am using Django-rest-auth for my authentication purposes, although, I have not been able to set it up. Anyway, I am trying to set up this app with my project. I realized I need to install django-rest-auth-registration to get it running, so I followed this documentation to do the following things:
I ran the commands
pip install django-rest-auth
and
pip install django-allauth
Any my settings.py looks like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 3rd party apps
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'allauth',
'allauth.account',
'rest_auth.registration',
# My app
'myapp',
]
I have also added the authentication backends, context_processors, and the proper urls.
However, when I try to migrate, my terminal throws the following error:
RuntimeError: Model class django.contrib.sites.models.Site doesn't
declare an explicit app_label and isn't in an application in
INSTALLED_APPS.
Why do I get this error, and how do I solve it to migrate my project? Thanks!
The fix
Just add Django's Sites framework to your apps and set SITE_ID to 1 in your settings.
INSTALLED_APPS = [
...
'django.contrib.sites',
]
SITE_ID = 1
Why does this happen?
Django's Sites Framework is a contributed module bundled with the core library that allows for the use of a single Django application/codebase with different sites (that can use different databases, logic in views, etc). The SITE_ID setting, as stated in the docs, "is used so that application data can hook into specific sites and a single database can manage content for multiple sites."
In this particular case AllAuth requires the Sites Framework in order to function properly. Many other third-party libraries are built to safely handle cases where multiple sites may be present and as such may be best .
I landed on this post via Google search. My problem was running tests that blew up with the error:
RuntimeError: Model class app.taxonomy.models.Term doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
This was running on Python 2.7.x with absolute imports. As mentioned by Colton Hicks in the comments, below, this can also happen with Python 3 (pytest 3.2.3 with Django 1.11.4).
In my tests.py:
from __future__ import absolute_import
[...]
from .models import Demographics, Term
After changing the relative import to an absolute import the problem went away:
from taxonomy.models import Demographics, Term
HTH
Try adding the app_label = 'yourApp' in the models Meta class:
class Meta:
app_label = 'yourApp'
I got the error above. However my problem was the in the urls.py. I was following PyDanny cookiecutter django recipe. My error was to put in the urls.py this line:
url(r'^demo/', include('project.demoapp.urls', namespace='demoapp')),
when I corrected to this:
url(r'^demo/', include('demoapp.urls', namespace='demoapp')),
all was well. I also changed my local apps (I did this first and so the critical error was the url misconfiguration):
LOCAL_APPS = [
# Your stuff: custom apps go here
'demoapp.apps.DemoAppConfig',
]
I have django debug toolbar installed and this was actually causing the/my problem.
INSTALLED_APPS (in settings.py) needs the entry 'django.contrib.sessions'. Make sure to run migrate after adding.
Just add 'django.contrib.sites', to INSTALLED_APPS and set SITE_ID = 1 in your settings.py file.
Upgraded Answer for Django>=4.0 // 2022
Add Django's Sites framework and FlatPages Framework to your INSTALLED_APPS and set SITE_ID in your settings.
INSTALLED_APPS = [
...
'django.contrib.sites',
'django.contrib.flatpages',
]
SITE_ID = 1
Your tests should work like a charm
This error occurred because I had created a new app folder for a subset of sites related to another feature. This needed to be added to my INSTALLED_APPS in settings.py
Django 4.1+ (2023)
After almost an hour digging, what solved for me was this:
INSTALLED_APPS = [
...
'django.contrib.sessions',
]
No need for SITE_ID or additional INSTALLED_APPS entries.
Everything worked as expected after I made a migration
python manage.py migrate
Good luck

Django-cms toolbar not showing on my project

To begin with, I have a problem with djangocms toolbar. I can't make it show when I append ?edit to the end of url.
Django version = 1.8.4
Django-cms version = 3.1.3
python = 2.7
What I think is the problem, is the fact that I have djangocms installed on a blog app from my entire project. I only want django-cms functionality on my /blog app
So, my project structure looks like this:
-project/
-blog/
-templates/
-__init__.py
-project/
-static/
-website/
-manage.py
-README.md
Now, I want to append toolbar to: mywebsite:8000/blog?edit but it's not working. Can't see any errors in shell console or web console.
urls.py (relevant part)
url(r'^blog/', include('cms.urls')),
The template part works as I can see the templates that I set in settings.py in CMS_TEMPLATES.
I also have CMS_PERMISSION=False (tried with true also), and the following to installed apps:
INSTALLED_APPS = (
'console_admin',
'djangocms_admin_style',
'blog',
'django.contrib.admin.apps.SimpleAdminConfig',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'project',
'adminplus',
'cms',
'mptt',
'menus',
'sekizai',
'reversion',
'treebeard',
)
I checked several tutorials from django-cms but unfortunately I had no success. Can anybody help me, please ? I really need to get this done.
You need {% cms_toolbar %} in your (base) template in order to ensure the template gets displayed across your site.
It's usually best placed right after the <body> tag in your base.html file.
Also if you define CMS_TOOLBAR_ANONYMOUS_ON in your settings as False you need to login via /admin/ before you can use /?edit to view the toolbar.

Upgrading Django 1.1.1 to 1.3.1, admin.autodiscover() raises exception asking for contenttypes

I switched a 1.1.1 Django project to 1.3.1. Upon calling admin.autodiscover() in urls.py, an exception is raised from sites.py in the admin framework stating:
ImproperlyConfigured at /
Put 'django.contrib.contenttypes' in your INSTALLED_APPS setting in order
to use the admin application
In settings.py, I have:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'my.app'
)
Things I checked:
The contenttypes framework is indeed in my INSTALLED_APPS setting.
I have not repeated my INSTALLED_APPS declaration anywhere else
The contenttypes entry in INSTALLED_APPS is listed before the admin entry.
Running django-admin.py shell and importing "django.contrib.contenttypes" works.
If I go to the offending lines in the admin (Django-1.3.1/django/contrib/admin/sites.py in check_dependencies, line 164), I see:
if not ContentType._meta.installed:
raise ImproperlyConfigured(...)
If I comment out the check, I can run my project and the admin works. I'm not sure how the _meta.installed property is supposed to be set on model types, so I am at a loss for what to do next.
I should also note that this same Django 1.3.1 installation is working with other projects using similar settings files.
Any hints or resources would be appreciated! Thanks!
django.contrib.contenttypes includes two models, ContentType and ContentTypeManager. My guess is that you haven't run manage.py syncdb after adding django.contrib.contenttypes to your INSTALLED_APPS.
This would make the if not ContentType._meta.installed check understandable: the ContentType model isn't available in the database yet.