cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

neomodel.exceptions.ClassAlreadyDefined

Hi Guys,

Im running into an issue using neomodel in my flask project.

When i'm trying to setup a relationship between 2 classes i keep running into the ClassAlreadyDefined exceptions. I suspect the problem is that I import the object in the controller. How can i overcome the exception? Feel free to ask any other information if necessary.

neomodel.exceptions.ClassAlreadyDefined: Class modules.crm.models.WorkOrder.WorkOrder with labels WorkOrder already defined:
{frozenset({'Customer'}): <class 'crm.models.Customer.Customer'>, frozenset({'WorkOrder'}): <class 'crm.models.WorkOrder.WorkOrder'>}

Models:

from neomodel import StringProperty, RelationshipFrom, ZeroOrMore, StructuredNode

from utilities.database.neo4j.BaseModel import BaseModel


class Customer(BaseModel):
    __label__ = "Customer"
    # Properties
    title = StringProperty(required=True)
    remarks = StringProperty()

    # Relations
    workorders = RelationshipFrom("modules.crm.models.WorkOrder.WorkOrder", "BELONGS_TO_CUSTOMER")

    def as_dict(self):
        return {
            'id': self.uuid,
            'title': self.title,
            'remarks': self.remarks
        }
from neomodel import StringProperty, RelationshipTo, One, StructuredNode

from utilities.database.neo4j.BaseModel import BaseModel


class WorkOrder(BaseModel):
    __label__ = "WorkOrder"
    # Properties
    title = StringProperty()
    customer_appointed_responsible = StringProperty()
    remarks = StringProperty()

    # Relations
    customer = RelationshipTo("modules.crm.models.Customer.Customer", "BELONGS_TO_CUSTOMER")

    def as_dict(self):
        return {
            'id': self.uuid,
            'title': self.title,
            'customer_appointed_responsible': self.customer_appointed_responsible,
            'remarks': self.remarks
        }

Controllers:

from flask.json import jsonify
from flask_cors import cross_origin

from crm.controllers.Controller import crm_blueprint
from crm.models.Customer import Customer
from utilities.project.NestedBlueprint import NestedBlueprint

customers_crm_blueprint = NestedBlueprint(crm_blueprint, 'customers')



@customers_crm_blueprint.route('', methods=['GET'])
@cross_origin()
def customers_index():
    customers = Customer.nodes.all()
    ret = list()
    for customer in customers:
        ret.append(customer.as_dict())
    return jsonify(ret)
from flask.json import jsonify
from flask_cors import cross_origin

from crm.controllers.Controller import crm_blueprint
from crm.models.WorkOrder import WorkOrder
from utilities.project.NestedBlueprint import NestedBlueprint

workorders_crm_blueprint = NestedBlueprint(crm_blueprint, 'workorders')

@workorders_crm_blueprint.route('', methods=['GET'])
@cross_origin()
def workorders_index():
    workorders = WorkOrder.nodes.all()
    ret = list()
    for workorder in workorders:
        ret.append(workorder.as_dict())
    return jsonify(ret)
0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online