我正在使用 webapp2,ndb 模型。
我试图将 django 模型表单与 ndb 模型一起使用。以下是我的设置中的相关部分:
应用程序.yaml:
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
- name: markupsafe
version: latest
- name: django
version: 1.3
模型.py:
class SubTask(ndb.Model):
task = ndb.StructuredProperty(TaskList)
description = ndb.TextProperty()
start_time = ndb.DateTimeProperty()
end_time = ndb.DateTimeProperty()
表格.py:
from django.forms import ModelForm
from models import TaskList, TaskCategory, SubTask
class SubTaskForm(ModelForm):
class Meta:
model = SubTask
处理程序:
class CreateSubTask(BaseHandler):
def get(self):
self.render_template('index.html', {'form':SubTaskForm})
app = webapp2.WSGIApplication([('/', IndexPage),
('/subtask', CreateSubTask), ],
debug=True)
我得到的错误是: AttributeError: type object 'SubTask' has no attribute '_meta'
我的问题:有没有办法可以将 django 模型表单与 ndb 一起使用,或者如果我犯了一个错误,那是什么?如果不是 django modelforms,ndb 模型是否适用于 WTForms?
下面附上堆栈跟踪:
ERROR 2012-06-23 03:25:58,770 wsgi.py:189]
Traceback (most recent call last):
File "/homeproject/expts/google_appengine/google/appengine/runtime/wsgi.py", line 187, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/homeproject/expts/google_appengine/google/appengine/runtime/wsgi.py", line 225, in _LoadHandler
handler = __import__(path[0])
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
description)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
description)
File "/homeproject/expts/google_appengine/tdl/main.py", line 18, in <module>
from views import IndexPage, CreateSubTask
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
description)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
description)
File "/homeproject/expts/google_appengine/tdl/views.py", line 4, in <module>
from forms import SubTaskForm
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
description)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/homeproject/expts/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
description)
File "/homeproject/expts/google_appengine/tdl/forms.py", line 4, in <module>
class SubTaskForm(ModelForm):
File "/homeproject/expts/google_appengine/lib/django_1_3/django/forms/models.py", line 205, in __new__
opts.exclude, opts.widgets, formfield_callback)
File "/homeproject/expts/google_appengine/lib/django_1_3/django/forms/models.py", line 145, in fields_for_model
opts = model._meta
AttributeError: type object 'SubTask' has no attribute '_meta'