geex-arts / django-jet

Modern responsive template for the Django admin interface with improved functionality. We are proud to announce completely new Jet. Please check out Live Demo
https://github.com/jet-admin/jet-bridge
GNU Affero General Public License v3.0
3.58k stars 772 forks source link

Unable to proceed after login for custom user #453

Open sanidhyamangal opened 4 years ago

sanidhyamangal commented 4 years ago

I have created a custom user model for my Django App. Everything is working fine without django-jet but when I use I use django jet then I receive the error which says argument of type 'QuerySet' is not iterable with following error trace :

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/

Django Version: 3.0.6
Python Version: 3.8.2
Installed Applications:
['jet',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'main']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error:
In template /home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/jet/templates/admin/base.html, error at line 199
   argument of type 'QuerySet' is not iterable
   189 :                             <span class="sidebar-link-label">
   190 :                                 <span class="sidebar-link-icon icon-book"></span>
   191 :                                 {% trans 'Documentation' %}
   192 :                             </span>
   193 :                         </a>
   194 :                     {% endif %}
   195 :                     {% block nav-global %}{% endblock %}
   196 :                 </div>
   197 : 
   198 :                 {% if user.is_active and user.is_staff %}
   199 :                      {% jet_get_menu as app_list %} 
   200 :                     {% if SIDE_MENU_COMPACT %}
   201 :                         {% for app in app_list %}
   202 :                             {% if app.has_perms %}
   203 :                                 <div class="sidebar-section">
   204 :                                     <div class="sidebar-title">
   205 :                                         <a{% if app.url %} href="{{ app.url }}"{% endif %} class="sidebar-title-link"{% if app.url_blank %} target="_blank"{% endif %}>
   206 :                                             {{ app.label }}
   207 :                                         </a>
   208 :                                     </div>
   209 :                                     {% for model in app.items %}

Traceback (most recent call last):
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 145, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 143, in _get_response
    response = response.render()
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/defaulttags.py", line 309, in render
    return nodelist.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 936, in render
    bit = node.render_annotated(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/django/template/library.py", line 192, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/jet/templatetags/jet_tags.py", line 47, in jet_get_menu
    return get_menu_items(context)
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/jet/utils.py", line 311, in get_menu_items
    original_app_list = OrderedDict(map(lambda app: (app['app_label'], app), get_original_menu_items(context)))
  File "/home/sanidhya/Py/goal_management/env/lib/python3.8/site-packages/jet/utils.py", line 286, in <lambda>
    'pinned': app['app_label'] in pinned_apps,

Exception Type: TypeError at /admin/
Exception Value: argument of type 'QuerySet' is not iterable

Sneak peak to my settings.py file:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

AUTH_USER_MODEL = 'main.User'

# Application definition

INSTALLED_APPS = [
    'jet',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'goal_management.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'goal_management.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

JET_THEMES = [
    {
        'theme': 'default', # theme folder name
        'color': '#47bac1', # color of the theme's button in user menu
        'title': 'Default' # theme title
    },
    {
        'theme': 'green',
        'color': '#44b78b',
        'title': 'Green'
    },
    {
        'theme': 'light-green',
        'color': '#2faa60',
        'title': 'Light Green'
    },
    {
        'theme': 'light-violet',
        'color': '#a464c4',
        'title': 'Light Violet'
    },
    {
        'theme': 'light-blue',
        'color': '#5EADDE',
        'title': 'Light Blue'
    },
    {
        'theme': 'light-gray',
        'color': '#222',
        'title': 'Light Gray'
    }
]

JET_SIDE_MENU_ITEMS = [  # A list of application or custom item dicts
    {
        'label': 'Users',
        'app_label':'auth',
        'items': [
            {
                'name': 'main.user'
            },
            {
                'name': 'auth.group'
            },
        ]
    },
    {
        'label':
        'Goal',
        'app_label':
        'main',
        'items': [{
            'name': 'main.goals'
        }]
    },
]

# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
akiyoko commented 4 years ago

You should migrate jet. See https://jet.readthedocs.io/en/latest/install.html#installation.

python manage.py migrate jet

I had the same problem, but migrating solved it.

sanidhyamangal commented 4 years ago

@akiyoko, I've already tried that still it is not working.