简体   繁体   中英

Does Neomodel support modelform? If so, why isn't it picking up default meta attributes / how do I set them?

I am getting AttributeError: type object 'Person' has no attribute '_meta' when trying to use Neomodel with Django's ModelForm. I'm new to using neomodel and do not know if Neomodel supports modelforms, but I've searched the docs and here for references without luck.

First Question, therefore is: does Neomodel support modelforms?

Second Question (if answer is yes to first): What is wrong with the following?

Models.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)

and my forms.py:

from django.forms import ModelForm
from .models import Person


class AddPersonForm(ModelForm):

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

In testing this at the django shell I get the following:

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'

I'm using Python 3.4.2, Django 1.7.7 and neomodel 1.0.2

Thanks!

I have two relationships Author-> Book and Book -> Author , but to import both class I have circular import error to define the relationship class type.

I solved using the absolute path to models as reference, do not import AuthorModel.

class BookModel(StructuredNode):
    title = StringProperty(unique_index=True)
    author = RelationshipTo('models.author.AuthorModel', 'AUTHOR')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM