【问题标题】:Define node with a unique property in neo4django在 neo4django 中定义具有唯一属性的节点
【发布时间】:2013-08-10 16:14:58
【问题描述】:

我在我的项目中定义了一个图形结构,目前包含两种类型的节点:用户和帖子。我已经在 Django 框架上安装了 neo4django 并定义了 models.py,如下所示:

from neo4django.db import models


class User(models.NodeModel):
    #firstname of the user that registered in first time
    firstName = models.StringProperty(max_length=20)

    #lastname of the user that registered in first time
    lastName = models.StringProperty(max_length=20)

    #password of user that selected by user
    password = models.StringProperty(max_length=50)

    #email that use for verification
    email = models.EmailProperty()

    #status of the user that can be 1 for online and 0 for offline
    status = models.BooleanProperty()

    #date of birth that user selected from the register form
    #BirthDate = models.DateProperty()

    #sex of the user that can be male and female (0=male,1=female)
    gender = models.BooleanProperty()

我想使用电子邮件地址和密码登录,然后电子邮件在数据库中必须是唯一的。如何在 models.py 中做到这一点?

【问题讨论】:

    标签: python django django-models neo4j neo4django


    【解决方案1】:

    您可以将unique=True 传递给任何Property 子类。唯一的属性必须被索引,所以:

    email = models.EmailProperty(indexed=True, unique=True)
    

    【讨论】:

    • 运行python manage.py syncdb 时出现此错误:ValueError: A unique property must be indexed.
    • @mojibuntu 更新了答案。
    • thanks.this works.你在哪里找到这个参数:D?我没有找到它们,您是否在特定资源中找到它们?
    • @mojibuntu 源代码是你最好的朋友......在 Github 的神秘土地上,你会找到你迫切寻求的答案。
    猜你喜欢
    • 2013-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多