I'm new to Django. Trying to migrate from django==1.8.5 to 1.11
django-hvad package is essential for me, however, when upgraded to django==1.10, it throws the assertion error about the Django version.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f407d733b70>
Traceback (most recent call last):
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/home/riddle/pro/blog/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/riddle/pro/blog/app/apps/frontend/website/models.py", line 116, in <module>
class ContentBlock(Common, TranslatableModel, OrderedModel):
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/db/models/base.py", line 309, in __new__
new_class._prepare()
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/db/models/base.py", line 359, in _prepare
signals.class_prepared.send(sender=cls)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 191, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/riddle/pro/blog/env/lib/python3.6/site-packages/hvad/models.py", line 447, in prepare_translatable_model
assert django.VERSION < (1, 10)
AssertionError
My project is actually a single-page website, so it is not a big hassle to remove django-hvad and use something else. That is my question therefore, what steps are better to take:
(1) try to use another "app" for model translation, as in:
https://djangopackages.org/grids/g/model-translation/
(however, as I see, only one package supports Django1.10 there).
(2) Or maybe Django has a native model translation option which I should use.
(3) another option
The strange thing also is that https://django-hvad.readthedocs.io/en/latest/index.html indicates that django1.9 is the last supported version, but in GitHub page https://github.com/kristianoellegaard/django-hvad it is written that django 1.10 as well as django 1.11 are supported.
Please indicate what more information is needed, I will try to provide.
My pip freeze output:
Django==1.10
django-appconf==1.0.2
django-compressor==2.2
django-filebrowser-no-grappelli==3.7.4
django-geoposition==0.3.0
django-hvad==1.8.0
django-jquery==3.1.0
django-libsass==0.7
django-ordered-model==1.4.3
django-tinymce==2.7.0
libsass==0.14.2
Pillow==5.1.0
psycopg2-binary==2.7.4
pytz==2018.3
rcssmin==1.0.6
rjsmin==1.0.12
six==1.11.0
Usage of django-hvad (example):
from hvad.models import TranslatableModel, TranslatedFields
class SliderBox(TranslatableModel, OrderedModel):
translations = TranslatedFields(
image = FileBrowseField(
"Image",
max_length=200,
directory="uploads/",
extensions=[".png", ".jpg"],
blank=True,
null=True
),
text = models.CharField(max_length=200),
)
Related
I am learning this Django Framework from this summer. I have get the error <TypeError: 'NoneType' object is not callable>. I am trying to narrow down the problem. However, after I have delete a lot of code, I still cannot figure this out from the most simple code. My code is showed as below.
admin.py
from django.contrib import admin
from rest_framework.renderers import AdminRenderer
from .models import Car
#admin.site.register(Car)
class CarAdmin(admin.ModelAdmin):
list_display = ('id', 'brand', 'model')
models.py
from django.db import models
from django.contrib import admin
class Car(models.Model):
brand = models.TextField(default='Honda')
model = models.TextField(default='EK9')
class Meta:
db_table = 'car'
def __str__(self):
return self.model
the error
LeodeMacBook-Pro:sharky leo$ python ./manage.py runserver
/Users/leo/opt/anaconda3/lib/python3.8/site-packages/environ/environ.py:628: UserWarning: /Users/leo/Documents/python_test/leo_first_python_side_project/sharky/sharky/mysite/.env doesn't exist - if you're not configuring your environment separately, create one.
warnings.warn(
/Users/leo/opt/anaconda3/lib/python3.8/site-packages/environ/environ.py:628: UserWarning: /Users/leo/Documents/python_test/leo_first_python_side_project/sharky/sharky/mysite/.env doesn't exist - if you're not configuring your environment separately, create one.
warnings.warn(
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/leo/opt/anaconda3/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/Users/leo/opt/anaconda3/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/leo/django/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/leo/django/django/core/management/commands/runserver.py", line 114, in inner_run
autoreload.raise_last_exception()
File "/Users/leo/django/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/Users/leo/django/django/core/management/__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "/Users/leo/django/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/leo/django/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/leo/django/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/Users/leo/django/django/contrib/admin/apps.py", line 27, in ready
self.module.autodiscover()
File "/Users/leo/django/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/Users/leo/django/django/utils/module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/Users/leo/opt/anaconda3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/leo/Documents/python_test/leo_first_python_side_project/sharky/sharky/car/admin.py", line 8, in <module>
class CarAdmin(admin.ModelAdmin):
TypeError: 'NoneType' object is not callable
environment
asgiref==3.4.1; python_version >= '3.6'
django-environ==0.4.5
django==3.2.6
pytz==2021.1
sqlparse==0.4.1; python_version >= '3.5'
what I have down
I have search the web of Django & Python and dozens of Questions on stack overflow.
I have realize that the most common solution is to remove the ().
However, I do not call the func. anywhere.
Therefore,I have raised this question to search for is there some mistake I do not understand about. Thanks for any advice/suggestion that help me to improve.
The error is from the #admin.site.register(Car)
this is because it returns None and wrapping CarAdmin with None is equivalent to doing CarAdmin = None(CarAdmin).
The solution is to use #admin.register(Car) instead
I'm trying to run a django code an imx6 yocto build that i made. The basic example went fine and smooth. So i decided to run my own django production from a project im working and i get the following:
root#imx6ulevk:/home/mdwb-main# python manage.py runserver 147.106.17.9:8000
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/usr/lib/python3.5/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python3.5/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/usr/lib/python3.5/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 985, in _gcd_import
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 693, in exec_module
File "<frozen importlib._bootstrap_external>", line 799, in get_code
File "<frozen importlib._bootstrap_external>", line 759, in source_to_code
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/mdwb-main/api_cloud/models.py", line 15
return f'{self.cloud_interval} foi cadastrado com sucesso!'
^
SyntaxError: invalid syntax
The code in models.py is the following:
from django.db import models
# Create your models here.
class Initial_config(models.Model):
#complement = models.CharField(max_length=30,null=True)
cloud_interval = models.IntegerField()
device_interval = models.IntegerField()
class Meta:
verbose_name = 'config'
verbose_name_plural = 'configs'
def __str__(self):
return f'{self.cloud_interval} foi cadastrado com sucesso!'
I tried to change the ' to " remove the {self.cloud_interval}, but none of them was sucessful.
Why this happens? How to fix it?
f-strings can only be used from Python 3.6 onwards.
If you want to remain with Python 3.5, you can change your code to:
def __str__(self):
return '%s foi cadastrado com sucesso!' % self.cloud_interval
That said, Python 3.5 is no longer officially supported; upgrading to 3.6 or above is highly recommended. See https://endoflife.date/python for more.
I am trying build a machine learning API using DJANGO rest framework API. After creating a project and configuring model.py of created project 'MyAPI' ,for required approvals. And used the following commend to run the server, got following error.
how to fix them ?, Please guide me.
````C:\Users\Padmini\DjangoAPI>python manage.py runserver```
error
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Padmini\DjangoAPI\MyAPI\models.py", line 4, in <module>
class approvals(models.Model):
File "C:\Users\Padmini\DjangoAPI\MyAPI\models.py", line 7, in approvals
('Female','Female')
TypeError: 'tuple' object is not callable````
my model.py as following code
from django.db import models
# Create your models here.
class approvals(models.Model):
GENDER_CHOICES= (
('Male', 'Male')
('Female','Female')
)
MARRIED_CHOICES=(
('Yes','Yes'),
('No','No')
)
GRADUATED_CHOICES= (
('Graduate','Graduated'),
('Not_Graduate','Not_Graduate')
)
SELFEMPLOYED_CHOICES=(
('Yes','Yes'),
('No','No')
)
PROPERTY_CHOICES=(
('Rural','Rural'),
('Semiurban','Semiurban'),
('Urban','Urban')
)
firstname=models.CharField(max_length=15)
lastname=models.CharField(max_length=15)
dependants=models.IntegerField(default=0)
applicantincome=models.IntegerField(default=0)
coapplicatincome=models.IntegerField(default=0)
loanamt=models.IntegerField(default=0)
loanterm=models.IntegerField(default=0)
credithistory=models.IntegerField(default=0)
gender=models.CharField(max_length=15, choices=GENDER_CHOICES)
married=models.CharField(max_length=15, choices=MARRIED_CHOICES)
graduatededucation=models.CharField(max_length=15, choices=GRADUATED_CHOICES)
selfemployed=models.CharField(max_length=15, choices=SELFEMPLOYED_CHOICES)
area=models.CharField(max_length=15, choices=PROPERTY_CHOICES)
def __str__(self):
return '{}, {}'.format(self.lastname, self.firstname)`````
class EmailUser(User):
class Meta:
proxy = True
email = models.EmailField(_('email address'), unique=True)
In the above, I'm trying to implement a proxy model, but I'm getting this error message:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10e04ed08>
Traceback (most recent call last):
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/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 "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/workout/workoutcal/models.py", line 28, in <module>
class EmailUser(User):
File "/Users/sahandzarrinkoub/Documents/Programming/Web/Django/workout/lib/python3.6/site-packages/django/db/models/base.py", line 231, in __new__
base.__name__,
django.core.exceptions.FieldError: Local field 'username' in class 'EmailUser' clashes with field of the same name from base class 'User'.
I wonder why I get this error, and what to do about it. I'm using Django version 1.11.
You can't do what you're trying to do with a proxy model. Luckily, Django makes it easy to extend the built-in User model: create a normal concrete model that inherits from AbstractUser, and set the AUTH_USER_MODEL setting to the name of your model.
Every time I update my models I have to delete and reinitialize the database.
./manage.py db init
and then initial
./manage.py db migrate
work but every subsequent ./manage.py db migrate fails with the following error:
INFO [alembic.migration] Context impl SQLiteImpl.
INFO [alembic.migration] Will assume non-transactional DDL.
Traceback (most recent call last):
File "manage.py", line 110, in <module>
manager.run()
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_script/__init__.py", line 405, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_script/__init__.py", line 384, in handle
return handle(app, *positional_args, **kwargs)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_script/commands.py", line 145, in handle
return self.run(*args, **kwargs)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages
/flask_migrate/__init__.py", line 80, in migrate
command.revision(config, message, autogenerate = True, sql = sql)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages /alembic/command.py", line 97, in revision
script.run_env()
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages /alembic/script.py", line 199, in run_env
util.load_python_file(self.dir, 'env.py')
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/util.py", line 199, in load_python_file
module = load_module(module_id, path)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/compat.py", line 49, in load_module
return machinery.SourceFileLoader(module_id, path).load_module()
File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
File "<frozen importlib._bootstrap>", line 1614, in load_module
File "<frozen importlib._bootstrap>", line 596, in _load_module_shim
File "<frozen importlib._bootstrap>", line 1220, in load
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "migrations/env.py", line 72, in <module>
run_migrations_online()
File "migrations/env.py", line 65, in run_migrations_online
context.run_migrations()
File "<string>", line 7, in run_migrations
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/environment.py", line 652, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages /alembic/migration.py", line 210, in run_migrations
self):
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/command.py", line 83, in retrieve_migrations
autogen._produce_migration_diffs(context, template_args, imports)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/api.py", line 143, in _produce_migration_diffs
autogen_context, object_filters, include_schemas)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/api.py", line 198, in _produce_net_changes
inspector, metadata, diffs, autogen_context)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/compare.py", line 69, in _compare_tables
diffs, autogen_context, inspector)
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/autogenerate/compare.py", line 223, in _compare_indexes_and_uniques
metadata_indexes
File "/home/sergi/.virtualenvs/flaskvenv/lib/python3.4/site-packages/alembic/ddl/sqlite.py", line 56, in correct_for_autogen_constraints
conn_uniques.remove(idx)
NameError: name 'conn_uniques' is not defined
I use the SQLite3 database. I had my models split into several files but put them in a single file but no help. I also tried upgrading flask-migrate, flask-sqlalchemy and other packages but also no help. What could be wrong?
Update:
I am using the Alembic version 0.6.2
It's really odd, but a few of the 0.6.x releases of Alembic appear to have this undefined symbol.
The mistake was corrected in release 0.6.7. Here is the commit that shows how this line was corrected: https://github.com/zzzeek/alembic/commit/ead05ce48d40d4235b2395972fd1a6efb96d414c
Pretty sure if you upgrade to 0.6.7 or newer the problem will be resolved.