I'm trying to use Django-nested-inlines application but it raises error. Here is a simple code:
MODELS.PY
class Language_Quiz(models.Model):
name = models.CharField(max_length=40)
language = models.OneToOneField(sfl_models.Language)
class Question(models.Model):
language_quiz = models.ForeignKey(Language_Quiz)
text = models.TextField()
class Answer(models.Model):
question = models.ForeignKey(Question,related_name='answers')
text = models.TextField()
correct = models.BooleanField()
ADMIN.PY
from django.contrib import admin
import models
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline
class AnswerInline(NestedTabularInline):
model = models.Answer
class QuestionInline(NestedTabularInline):
model = models.Question
class LanguageQuizAdmin(NestedModelAdmin):
inlines = [QuestionInline]
admin.site.register(models.Language_Quiz,LanguageQuizAdmin)
admin.site.register(models.Answer)
admin.site.register(models.Question)
But when I run server or try to make migrations, the error is raised. I have no idea where is the problem. Where is the problem?
TRACEBACK
(venv) C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
utility.execute()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\core\management\__init__.py", line 328, in execute
django.setup()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\apps\registry.py", line 115, in populate
app_config.ready()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready
self.module.autodiscover()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\utils\module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\language_tests\admin.py", line 3, in <module>
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\nested_inlines\admin.py", line 16, in <module>
class NestedModelAdmin(ModelAdmin):
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\nested_inlines\admin.py", line 131, in NestedModelAdmin
#transaction.commit_on_success
AttributeError: 'module' object has no attribute 'commit_on_success'
As Kapil Sachdev and karthikr commented, the problem is with compatibility. Django-nested-inlines has probably some issues working with Django 1.8+.
In my case, the solution was very simple. Download using pip Django-nested-inline (without 's' at the end of the 'inline') and just change import. I didn't even have to change the code.
Related
This issue is appearing in paramiko v2 (2.4.2) and not in paramiko v1 (1.18.5).
Keys are stored in the known_hosts file.
I'm using the following code
import paramiko
ssh_client = paramiko.SSHClient()
ssh_client.load_system_host_keys()
ssh_client.connect(hostname='hostname', username='user', password='pass')
load_system_host_keys() fails and I'm getting this traceback:
Traceback (most recent call last):
File "/snap/pycharm-community/85/helpers/pydev/pydevd.py", line 1664, in <module>
main()
File "/snap/pycharm-community/85/helpers/pydev/pydevd.py", line 1658, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/snap/pycharm-community/85/helpers/pydev/pydevd.py", line 1068, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/administrator/rs_autolabs/utils/test.py", line 9, in <module>
ssh_client.load_system_host_keys()
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 104, in load_system_host_keys
self._system_host_keys.load(filename)
File "/usr/local/lib/python2.7/dist-packages/paramiko/hostkeys.py", line 97, in load
e = HostKeyEntry.from_line(line, lineno)
File "/usr/local/lib/python2.7/dist-packages/paramiko/hostkeys.py", line 356, in from_line
key = RSAKey(data=decodebytes(key))
File "/usr/local/lib/python2.7/dist-packages/paramiko/rsakey.py", line 69, in __init__
).public_key(default_backend())
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 15, in default_backend
from cryptography.hazmat.backends.openssl.backend import backend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/openssl/backend.py", line 16, in <module>
from cryptography import utils, x509
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/base.py", line 16, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/extensions.py", line 24, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/general_name.py", line 18, in <module>
from cryptography.x509.name import Name
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <module>
_ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <genexpr>
_ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
AttributeError: 'int' object has no attribute 'value'
The solution is an issue with the enum module.
cryptography uses enum34.
I had my own implementation to enum in 'enum.py' file that was in the same package of my code.
cryptography tried to use this module instead of enum34.
reaming my 'enum.py' file to something else solved it.
read here:
python's cryptography throwing AttributeError: 'int' object has no attribute 'value'
thats my code in modeles.py
from django.db import models
from django.utils import timezone
class Book(models.Model):
title = models.CharField(max_length = 200)
author = models.CharField(max_lenght = 200)
description = models.TextField()
publish_date = models.DateField(Default= timezone.now)
that is when i type ./manage.py makemigrations execution error
that is what i see in shh
still error there is no control space to know when i pointer to mouse to django it appears unresolved reference 'django' while i installed it pip install django==1.8 and i run every time sudo pip install --ignore-installed virtualenvwrapper because when i use workon bookstore-django it does not execute until i run sudo pip install --ignore-installed virtualenvwrapper i am too beginner in this field
(bookstore-django) bavlys-Mac:bookstore bavlymorcos$ ./manage.py makemigrations store
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/bavlymorcos/Desktop/development/bookstore/store/models.py", line 6, in <module>
class Book(models.Model):
File "/Users/bavlymorcos/Desktop/development/bookstore/store/models.py", line 10, in Book
publish_date = models.DateField(Default=timezone.now)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1201, in __init__
super(DateField, self).__init__(verbose_name, name, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'Default'
The Charfield part should be CharField.
In /Users/bavlymorcos/Desktop/development/bookstore/store/models.py, line no. 6,
it should be
title = models.CharField(max_length = 200)
ie. F in field should be Capital. (CharField instead of Charfield)
Docs: https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.CharField
I solved the problem thanks guys
the problem was in model.py I changed it to like that
from django.db import models
from django.utils import timezone
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=200)
description = models.TextField()
publish_date = models.DateField(default=timezone.now)
I'm working with django 1.7 and i have created this management command:
File structure:
app/
__init__.py
management/
__init__.py
commands/
__init__.py
modal_asign.py
Code:
from django.core.management.base import BaseCommand, CommandError
from webinar.models import Webinar
class Commands(BaseCommand):
help = 'Assign modal link to every webinar'
def handle(self):
latest_webinar = Webinar.objects.all().order_by('-webinar_date')[0]
for webinars in latest_webinar:
print "http://webinar.academiaa2.com/webinars/#displayModal" + webinars
and i'm getting this error when trying to test it with python manage.py modal_asign
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 238, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 42, in load_command_class
return module.Command()
AttributeError: 'module' object has no attribute 'Command'
Your class name is called Commands, whereas django expects it to be called Command. Hence the error.
Change
class Commands(BaseCommand):
to
class Command(BaseCommand):
I' ve got an issue when running freeswitch with some python scripts inside dialplan using django.db models. Whenever it starts it causes errors:
freeswitch#ubuntu> 2013-08-15 06:56:08.094348 [ERR] mod_python.c:231 Error importing module
2013-08-15 06:56:08.094348 [ERR] mod_python.c:164 Python Error by calling script "fs_scripts.ringback": <type 'exceptions.IOError'>
Message: [Errno 10] No child processes
Exception: None
Traceback (most recent call last)
File: "/home/piotrek/lettel/fs_scripts/ringback.py", line 19, in <module>
File: "/home/piotrek/lettel/api/call.py", line 3, in <module>
File: "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 11, in <module>
File: "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
File: "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
File: "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 93, in __init__
File: "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
File: "/home/piotrek/lettel/lettel/settings.py", line 13, in <module>
File: "/usr/local/lib/python2.7/dist-packages/djcelery/__init__.py", line 25, in <module>
File: "/usr/local/lib/python2.7/dist-packages/celery/__compat__.py", line 135, in __getattr__
File: "/usr/local/lib/python2.7/dist-packages/celery/_state.py", line 19, in <module>
File: "/usr/local/lib/python2.7/dist-packages/celery/utils/__init__.py", line 22, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/entity.py", line 10, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/abstract.py", line 12, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 24, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/log.py", line 8, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/utils/compat.py", line 68, in <module>
File: "/usr/lib/python2.7/platform.py", line 1337, in system
File: "/usr/lib/python2.7/platform.py", line 1304, in uname
File: "/usr/lib/python2.7/platform.py", line 1039, in _syscmd_uname
edit: the line that causes errors is a simple import from django.db:
from django.db import models
This whole setup is already running on some server that I dont have access to, so it seems to be nothing wrong with django app or scripts...
Any help would be appreciated cause I am running out of ideas how to solve this problem...
I dont know your performance and scalability requirements, despite that a softswitch have realtime requirements to run rtp stream and signalling. So is not a good solution run django applications under mod_python. Furthermore that is not the same as python interpreter directly, somethings does not work. You can check the mod_python issues here:
mod_python issues
I would advice you to split your python solution in a client/server architecture. The script running under mod_python will make queries to your Django application. That way you will get rid of the complexity in Freeswitch side, get scalable, improve performance and most probably get everything working OK.
I'm experimenting with Page extensions and FeinCMS 1.2.1.
I'd like to create this simple page extension:
from django.db import models
def register(cls, admin_cls):
cls.add_to_class(models.TextField())
but I keep getting this error:
AttributeError: 'module' object has no attribute 'TextField'
The package containing the extension is called dev.extensions and the module categories, I have added it to the Python path and the extension is registered with Page.register_extensions('dev.extensions.categories').
I'm wondering what I'm doing wrong, please help.
The complete stacktrace follows.
c:\sandbox\projects\feindev>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_manager(settings)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 436, in execute_m
anager
setup_environ(settings_mod)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 419, in setup_env
iron
project_module = import_module(project_name)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "c:\sandbox\projects\feindev\..\fein
dev\__init__.py", line 52, in <module>
Page.register_extensions('dev.extensions.types')
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\models.py", line 270, in register_extensions
cls.register_extension(fn)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\module\page\models.py", line 564, in register_exten
sion
register_fn(cls, PageAdmin)
File "c:\sandbox\projects\feindev\dev\ext
ensions\types\__init__.py", line 4, in register
cls.add_to_class(models.TextField())
AttributeError: 'module' object has no attribute 'TextField'
Maybe models is getting reassigned somewhere to another module before your register function gets run?
Try changing your code to this:
from django.db import models as django_models
def register(cls, admin_cls):
cls.add_to_class('field_name_here', django_models.TextField())