![](/img/trans.png)
[英]How Do I Set Up Python Imports Correctly and so I Don't have to manually download them?
[英]Does Neomodel support modelform? If so, why isn't it picking up default meta attributes / how do I set them?
嘗試將 Neomodel 與 Django 的 ModelForm 一起使用時,出現AttributeError: type object 'Person' has no attribute '_meta' 。 我是使用 neomodel 的新手,不知道 Neomodel 是否支持 modelforms,但我已經搜索了文檔和這里的參考資料,但運氣不佳。
因此,第一個問題是: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
謝謝!
我有兩個關系Author-> Book
和Book -> Author
,但是要導入這兩個類,我有循環導入錯誤來定義關系類類型。
我解決了使用模型的絕對路徑作為參考,不導入AuthorModel。
class BookModel(StructuredNode):
title = StringProperty(unique_index=True)
author = RelationshipTo('models.author.AuthorModel', 'AUTHOR')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.