My head hurts from beating it against this wall ... Why can't the content panels recognize the fields in my DetailPage? Everything works fine until I add the FieldPanels to the content_panels.
Oh, this is using the 2.0 version of wagtail also. This doesn't seem to be related to the field types, event a simple CharBlock triggers this error.
STACK TRACE
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000005F7CDB5598>
Traceback (most recent call last):
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 566, in get_field
return self.fields_map[field_name]
KeyError: 'links'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
...
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 766, in get_edit_handler
return edit_handler.bind_to_model(cls)
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 130, in bind_to_model
new.on_model_bound()
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in on_model_bound
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in <listcomp>
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 130, in bind_to_model
new.on_model_bound()
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in on_model_bound
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 275, in <listcomp>
for child in self.children]
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 130, in bind_to_model
new.on_model_bound()
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\wagtail\admin\edit_handlers.py", line 479, in on_model_bound
self.db_field = self.model._meta.get_field(self.field_name)
File "C:\Users\RichardK\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 568, in get_field
raise FieldDoesNotExist("%s has no field named '%s'" % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: DetailPage has no field named 'links'
models.py
from django.db import models
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.core import blocks
from wagtail.core.blocks import ListBlock, URLBlock, StructBlock, TextBlock, CharBlock
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.search import index
class DetailPage(Page):
"""
Two column detail page with quick links on the left
"""
links = blocks.ListBlock(blocks.URLBlock(), null=True, blank=True)
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('links', classname="full"),
FieldPanel('body')
]
ListBlock and other block types such as CharBlock are not interchangeable with Django's model fields - they cannot be used directly within a page model definition, only within a StreamField.
Related
I am trying to load the ontology but I get an error that you can see in the post, the code is shown below.
Code:
from owlready2 import *
import os
onto = get_ontology("file://C:/Users/achev/Documents/Carro.owl")
onto.load()
n_classes = len(list(onto.classes()))
print(n_classes)
Error:
File "c:/Users/achev/Desktop/Proyecto de grado/Python/prueba.py", line 4, in <module>
onto = get_ontology("file://C:/Users/achev/Documents/Carro.owl").load()
File "C:\ProgramData\Anaconda3\lib\site-packages\owlready2\namespace.py", line 810, in load
if self.world.graph.indexed: self._load_properties()
File "C:\ProgramData\Anaconda3\lib\site-packages\owlready2\namespace.py", line 849, in _load_properties
raise TypeError("'%s' belongs to more than one entity types (cannot be both a property and a class/an individual)!" % Prop.iri)
I'm running the code cell below from https://github.com/aws-samples/amazon-sagemaker-stock-prediction/blob/master/notebooks/dbg-custom-rnn.ipynb , on SageMaker Notebook instance. For more information, here is the link to the error I posted on GitHub: https://github.com/aws-samples/amazon-sagemaker-stock-prediction/issues/7.
%%time
Instantiate estimator with container image of artifact and backend EC2 instance(s)
rnn = Estimator(image,
role, 1, 'ml.c5.18xlarge',
output_path=output_location,
base_job_name = base_job_name,
sagemaker_session=session)
rnn.set_hyperparameters(**hyperparameters)
Train the model
rnn.fit(data_location)
estimator_job = rnn.latest_training_job.job_name
model_archive = "{}/{}/output/{}/output/model.tar.gz".format(artifactname,interval,estimator_job)
print("Estimator created at completion of training job {}".format(estimator_job))
And I hit the error below:
Parameter image_name will be renamed to image_uri in SageMaker Python SDK v2.
's3_input' class will be renamed to 'TrainingInput' in SageMaker Python SDK v2.
2020-08-12 15:58:15 Starting - Starting the training job...
2020-08-12 15:58:17 Starting - Launching requested ML instances......
2020-08-12 15:59:38 Starting - Preparing the instances for training...
2020-08-12 16:00:16 Downloading - Downloading input data...
2020-08-12 16:00:22 Training - Downloading the training image...
2020-08-12 16:01:13 Uploading - Uploading generated training model.2020-08-12 16:01:08.786584: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-08-12 16:01:08.786650: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Starting the training.
Hyperparameters file : {"target_stock": "BMW", "lag": "10", "interval": "D", "batch_size": "4096", "covariate_columns": "StartPrice, MinPrice, MaxPrice", "percent_train": "85.0", "covariate_stocks": "CON, DAI, PAH3, VOW3", "dropout_ratio": "0.1", "num_epochs": "1000", "target_column": "EndPrice", "horizon": "5", "num_units": "256"}
Hyperparameters initialized
Loading data from : /opt/ml/input/data/training/resampled_stockdata.csv
Loading data from : /opt/ml/input/data/training/resampled_stockdata.csv
Training data loaded
100 Stock symbols found.
Records for 65 trading days found.
0-CON#0111-DAI#0112-PAH3#0113-VOW3
Exception during training: invalid syntax (core.py, line 314)
Traceback (most recent call last):
File "/opt/program/train", line 255, in train
traindata.to_csv(os.path.join(model_path, trainfile))
File "/usr/local/lib/python3.5/dist-packages/pandas/core/generic.py", line 3020, in to_csv
formatter.save()
File "/usr/local/lib/python3.5/dist-packages/pandas/io/formats/csvs.py", line 157, in save
compression=self.compression)
File "/usr/local/lib/python3.5/dist-packages/pandas/io/common.py", line 344, in _get_handle
from s3fs import S3File
File "/usr/local/lib/python3.5/dist-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/usr/local/lib/python3.5/dist-packages/s3fs/core.py", line 8, in <module>
from fsspec import AbstractFileSystem
File "/usr/local/lib/python3.5/dist-packages/fsspec/__init__.py", line 10, in <module>
from .mapping import FSMap, get_mapper
File "/usr/local/lib/python3.5/dist-packages/fsspec/mapping.py", line 2, in <module>
from .core import url_to_fs
File "/usr/local/lib/python3.5/dist-packages/fsspec/core.py", line 314
out[0] = (f"{out[0][1]}://", out[0][1], out[0][2])
^
SyntaxError: invalid syntax
2020-08-12 16:01:19 Failed - Training job failed
UnexpectedStatusException Traceback (most recent call last)
<timed exec> in <module>
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name, experiment_config)
497 self.jobs.append(self.latest_training_job)
498 if wait:
--> 499 self.latest_training_job.wait(logs=logs)
500
501 def _compilation_job_name(self):
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/estimator.py in wait(self, logs)
1114 # If logs are requested, call logs_for_jobs.
1115 if logs != "None":
-> 1116 self.sagemaker_session.logs_for_job(self.job_name, wait=True, log_type=logs)
1117 else:
1118 self.sagemaker_session.wait_for_job(self.job_name)
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/session.py in logs_for_job(self, job_name, wait, poll, log_type)
3075
3076 if wait:
-> 3077 self._check_job_status(job_name, description, "TrainingJobStatus")
3078 if dot:
3079 print()
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/session.py in _check_job_status(self, job, desc, status_key_name)
2669 ),
2670 allowed_statuses=,
-> 2671 actual_status=status,
2672 )
2673
UnexpectedStatusException: Error for Training job dbg-custom-rnn-D-BMW-2020-08-12-15-58-15-812: Failed. Reason: AlgorithmError: Exception during training: invalid syntax (core.py, line 314)
Traceback (most recent call last):
File "/opt/program/train", line 255, in train
traindata.to_csv(os.path.join(model_path, trainfile))
File "/usr/local/lib/python3.5/dist-packages/pandas/core/generic.py", line 3020, in to_csv
formatter.save()
File "/usr/local/lib/python3.5/dist-packages/pandas/io/formats/csvs.py", line 157, in save
compression=self.compression)
File "/usr/local/lib/python3.5/dist-packages/pandas/io/common.py", line 344, in _get_handle
from s3fs import S3File
File "/usr/local/lib/python3.5/dist-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/usr/local/lib/python3.5/dist-packages/s3fs/core.py", line 8, in <module>
from fsspec import AbstractFileSystem
File "/usr/local/lib/python3.5/dist-packages/fsspec/__init__.py", line 10, in <module>
from .mapping import FSMap, get_mapper
File "/usr/local/lib/python3.5/dist-packages/fsspec/map
Could anyone explain for me how to solve this error.
Thank you so much!
Rename s3_input to TrainingInput and remove warning message.
May be this will help you https://github.com/aws/sagemaker-python-sdk/pull/1680
I've used Wagtail's ModelAdmin on a few other projects with great success, but this is the first time I'm attempting to use it with a model inheriting from Page.
I copied the simple example template and removed the parts that didn't relate to my BlogPageModel.
The link to the ModelAdmin appears as expected, but when I click it, I get TemplateDoesNotExist at /admin/blog/blogpage/.
I don't remember having to set up a template before. Is there a setting I'm missing?
Wagtail: 1.9 /
Django: 1.10.5 /
Python: 3.5.2
Update: I tried it with a model that inherits from models.Model as well with the same result.
Traceback follows:
Internal Server Error: /admin/blog/blogpage/
Traceback (most recent call last):
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 39, in inner
response = get_response(request)
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
response = self._get_response(request)
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_response
response = response.render()
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/response.py", line 109, in render
self.content = self.rendered_content
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/response.py", line 84, in rendered_content
template = self.resolve_template(self.template_name)
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/response.py", line 66, in resolve_template
return select_template(template, using=self.using)
File "/Users/username/.virtualenv/lib/python3.5/site-packages/django/template/loader.py", line 53, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: modeladmin/blog/blogpage/index.html, modeladmin/blog/index.html, modeladmin/index.html
[21/Feb/2017 07:56:38] "GET /admin/blog/blogpage/ HTTP/1.1" 500 110901
I suspect you've missed out adding 'wagtail.contrib.modeladmin' to INSTALLED_APPS.
Use the example code from app engine will give an attribute error. The more strange thing is,
When the batch_size is 100, the first fetch will give an error while if it were set to 10, the second fetch will give the error, when the batch_size is 1, the 25th fetch will give the error. Is it due to the problem of remote API?
Python version: 2.7
App engine sdk version: 1.9.6
query = MyModel.all()
entities = query.fetch(100)
while entities:
for entity in entities:
# Do something with entity
query.with_cursor(query.cursor())
entities = query.fetch(100)
error message:
Traceback (most recent call last):
File "migrate.py", line 77, in <module>
entities = query.fetch(batch_size)
File "/home/kamel/Library/google_appengine/google/appengine/ext/db/__init__.py", line 2157, in fetch
return list(self.run(limit=limit, offset=offset, **kwargs))
File "/home/kamel/Library/google_appengine/google/appengine/ext/db/__init__.py", line 2326, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/home/kamel/Library/google_appengine/google/appengine/ext/db/__init__.py", line 1435, in from_entity
entity_values = cls._load_entity_values(entity)
File "/home/kamel/Library/google_appengine/google/appengine/ext/db/__init__.py", line 1413, in _load_entity_values
value = prop.make_value_from_datastore(value)
File "/home/kamel/labola/src/model/properties.py", line 295, in make_value_from_datastore
return pickle.loads(value)
File "/usr/lib/python2.7/pickle.py", line 1382, in loads
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 1083, in load_newobj
obj = cls.__new__(cls, *args)
AttributeError: class Reference has no attribute '__new__
I encountered the same issue when trying to unpickle python3 pickles under python2. The problem was linked to new-style classes becoming default in python3. (source)
Solution for me was to replace class AClass: by class AClass(object):
I read the "what is a metaclass in Python" but am still confused over it.
I am new to python and have been thrown into upgrading it from 2.5 to 2.7.
I have the following:
class UsersDB(db.Model):
Email = db.EmailProperty(required=True,verbose_name='Email *')
Enable = db.BooleanProperty(default=True)
and
class UsersQuickAddForm(forms.ModelForm):
def is_user_exist(self, account):
users_query = UsersDB.all().filter('Email =', account).fetch(1)
if len(users_query) > 0:
return True
return False
class Meta:
model = UsersDB
exclude = ['Enable']
but when I try to execute it on the google site, I get:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 84, in LoadObject
obj = import(path[0])
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/LDSGH.py", line 8, in
from core.decorators import permissionRequired
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/decorators.py", line 7, in
from core.initialization import loginIf
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/initialization.py", line 6, in
import photo_images
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/photo_images.py", line 1, in
from core.db_models import ImagesDB
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/core/db_models.py", line 222, in
class UsersQuickAddForm(forms.ModelForm):#only account, firstname and last name is required
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/django/forms/models.py", line 205, in new
opts.exclude, opts.widgets, formfield_callback)
File "/base/data/home/apps/s~ldsdgidev/glen27.371429613087607751/django/forms/models.py", line 145, in fields_for_model
opts = model._meta
AttributeError: type object 'UsersDB' has no attribute '_meta'
and I don't understand what I need to add to the UserDB class to get rid of the error.
Any help would be great!
This isn't anything to do with Python versions, or metaclasses.
ModelForms only work with Django models. db.Model is the App Engine model class, not the Django one. You can't use a modelform with that class.
You mention django-nonrel in your question tags. That project allows you to use the Django models - subclasses of models.Model with the App Engine datastore. You probably want to do that.