Wednesday, August 16, 2017

Re: Cannot call imported models in views

Hi,

at some point in your code you have "import pprint". Replace it with "from pprint import pprint".

Regards,

Antonis

Antonis Christofides  http://djangodeployment.com
On 2017-08-16 12:57, Ladislav Brodecký wrote:
Hi, I installed newest django version and python 3.6 on CentOS 7 together with postgresql and I get this error everytime I try to call model class in views. I even tried MariaDB instead and I get same error.

Traceback (most recent call last):
 
File "manage.py", line 22, in <module>
    execute_from_command_line
(sys.argv)
 
 
File
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py",
 line
363, in execute_from_command_line
    utility
.execute()
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
   
self.fetch_command(subcommand).run_from_argv(self.argv)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
   
self.execute(*args, **cmd_options)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 327, in execute
   
self.check()
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks
=include_deployment_checks,
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
   
return checks.run_checks(**kwargs)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors
= check(app_configs=app_configs)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
   
return check_resolver(resolver)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
   
return check_method()
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py", line 254, in check
   
for pattern in self.url_patterns:
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res
= instance.__dict__[self.name] = self.func(instance)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns
= getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res
= instance.__dict__[self.name] = self.func(instance)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
   
return import_module(self.urlconf_name)
 
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
   
return _bootstrap._gcd_import(name[level:], package, level)
 
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
 
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
 
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
 
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
 
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
 
File "/python_apps/hotshot/project/project/urls.py", line 20, in <module>
   
from cost import views as cost_est_views
 
File "/python_apps/hotshot/project/cost/views.py", line 13, in <module>
    pprint
(cost.models.options_group)
TypeError: 'module' object is not callable
(env) [root@terra-1 project]# python manage.py migrate
Traceback (most recent call last):
 
File "manage.py", line 22, in <module>
    execute_from_command_line
(sys.argv)
 
 
File
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py",
 line
363, in execute_from_command_line
    utility
.execute()
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
   
self.fetch_command(subcommand).run_from_argv(self.argv)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
   
self.execute(*args, **cmd_options)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 327, in execute
   
self.check()
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks
=include_deployment_checks,
 
 
File
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/commands/migrate.py",
 line
62, in _run_checks
    issues
.extend(super(Command, self)._run_checks(**kwargs))
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py", line 346, in _run_checks
   
return checks.run_checks(**kwargs)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors
= check(app_configs=app_configs)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py", line 16, in check_url_config
   
return check_resolver(resolver)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py", line 26, in check_resolver
   
return check_method()
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py", line 254, in check
   
for pattern in self.url_patterns:
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res
= instance.__dict__[self.name] = self.func(instance)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns
= getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res
= instance.__dict__[self.name] = self.func(instance)
 
File "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
   
return import_module(self.urlconf_name)
 
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
   
return _bootstrap._gcd_import(name[level:], package, level)
 
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
 
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
 
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
 
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
 
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
 
File "/python_apps/hotshot/project/project/urls.py", line 20, in <module>
   
from cost import views as cost_est_views
 
File "/python_apps/hotshot/project/cost/views.py", line 13, in <module>
    pprint
(cost.models.options_group)
TypeError: 'module' object is not callable


Models:
from django.db import models

# Create your models here.
class options_group(models.Model):
    title
= models.TextField()
    description
= models.TextField(default=None, null=True, blank=True)
    chain
= models.ForeignKey('self', blank=True, null=True)

class options(models.Model):
    title
= models.TextField()
    description
= models.TextField(default=None, null=True, blank=True)
   
group =  models.ForeignKey(
        options_group
,
        on_delete
=models.CASCADE,
   
)
    price
= models.IntegerField(default=0)

Views:

from cost.models import *
pprint
(options_group)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9bbee8c5-665c-47ad-9c19-e0611da71dae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment