0

我在我的项目中定义了一个图形结构,该结构目前包含两种类型的节点:用户和帖子。我已经在 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中做到这一点?

4

1 回答 1

1

您可以传递unique=True给任何子Property类。必须对唯一属性进行索引,因此:

email = models.EmailProperty(indexed=True, unique=True)
于 2013-08-10T16:46:18.407 回答