4

尝试将 Neomodel 与 Django 的 ModelForm 一起使用时,出现 AttributeError:类型对象“Person”没有属性“_meta” 。我是使用 neomodel 的新手,不知道 Neomodel 是否支持模型形式,但我已经搜索了文档和此处的参考资料,但没有运气。

因此,第一个问题是:Neomodel 是否支持模型形式?

第二个问题(如果第一个问题的答案是肯定的):以下有什么问题?

模型.py

from neomodel import (StructuredNode, StringProperty, IntegerProperty, RelationshipTo)


class Person (StructuredNode):
    #Properties
    email = StringProperty(unique_index=True, required=True)
    name = StringProperty(unique_index=False, required=True)

和我的forms.py:

from django.forms import ModelForm
from .models import Person


class AddPersonForm(ModelForm):

    class Meta:
        model = Person
        fields = ['email','name']

在 django shell 中对此进行测试时,我得到以下信息:

from devsite_neo.forms import AddPerson

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Dev\www\repos\devsite\devsite_neo\forms.py", line 7, in <module> 
    class AddPerson(ModelForm):
File "c:\Dev\www\venv\djangoenv\lib\site-packages\django\forms\models.py", line 284, in __new__
    opts.help_texts, opts.error_messages)
File "c:\Dev\www\venv\djangoenv\lib\site-packages\django\forms\models.py", line 184, in fields_for_model
    opts = model._meta
AttributeError: type object 'Person' has no attribute '_meta'

我正在使用 Python 3.4.2、Django 1.7.7 和 neomodel 1.0.2

谢谢!

4

1 回答 1

0

我有两个关系Author-> BookBook -> Author,但是要导入两个类,我有循环导入错误来定义关系类类型。

我解决了使用模型的绝对路径作为参考,不要导入AuthorModel。

class BookModel(StructuredNode):
    title = StringProperty(unique_index=True)
    author = RelationshipTo('models.author.AuthorModel', 'AUTHOR')
于 2021-11-03T15:02:59.333 回答