How to use the neomodel.UniqueIdProperty function in neomodel

To help you get started, we’ve selected a few neomodel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_array_of_points():
    """
    Tests that Arrays of Points work as expected.

    :return:
    """

    class AnotherLocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity with an array of locations
        """
        identifier = neomodel.UniqueIdProperty()
        locations = neomodel.ArrayProperty(neomodel.contrib.spatial_properties.PointProperty(crs='cartesian'))

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    an_object = AnotherLocalisableEntity(locations=
                                         [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))]).save()

    retrieved_object = AnotherLocalisableEntity.nodes.get(identifier=an_object.identifier)

    assert type(retrieved_object.locations) is list, "Array of Points definition failed."
    assert retrieved_object.locations == [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))], \
        "Array of Points incorrect values."
github neo4j-contrib / neomodel / test / test_issue283.py View on Github external
def redefine_class_locally():
        # Since this test has already set up a class hierarchy in its global scope, we will try to redefine
        # SomePerson here.
        # The internal structure of the SomePerson entity does not matter at all here.
        class SomePerson(BaseOtherPerson):
            uid = neomodel.UniqueIdProperty()
github neo4j-contrib / django-neomodel / tests / someapp / models.py View on Github external
from datetime import datetime

from django.db import models
from django_neomodel import DjangoNode
from neomodel import StringProperty, DateTimeProperty, UniqueIdProperty


class Library(models.Model):
    name = models.CharField(max_length=10)

    class Meta:
        app_label = 'someapp'


class Book(DjangoNode):
    uid = UniqueIdProperty()
    condition = StringProperty(default='new')  # check fields can be omitted
    format = StringProperty(required=True)  # check required field can be ommitted on update
    title = StringProperty(unique_index=True)
    status = StringProperty(choices=(
            ('Available', 'A'),
            ('On loan', 'L'),
            ('Damaged', 'D'),
        ), default='Available')

    created = DateTimeProperty(default=datetime.utcnow)

    class Meta:
        app_label = 'someapp'
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_default_value():
    """
    Tests that the default value passing mechanism works as expected with NeomodelPoint values.
    :return:
    """

    def get_some_point():
        return neomodel.contrib.spatial_properties.NeomodelPoint((random.random(),random.random()))

    class LocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity to try out the default value assignment.
        """
        identifier = neomodel.UniqueIdProperty()
        location = neomodel.contrib.spatial_properties.PointProperty(crs='cartesian', default=get_some_point)

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')
    
    # Save an object
    an_object = LocalisableEntity().save()
    coords = an_object.location.coords[0]
    # Retrieve it
    retrieved_object = LocalisableEntity.nodes.get(identifier=an_object.identifier)
    # Check against an independently created value
    assert retrieved_object.location == neomodel.contrib.spatial_properties.NeomodelPoint(coords), \
        "Default value assignment failed."
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_array_of_points():
    """
    Tests that Arrays of Points work as expected.

    :return:
    """

    class AnotherLocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity with an array of locations
        """
        identifier = neomodel.UniqueIdProperty()
        locations = neomodel.ArrayProperty(neomodel.contrib.spatial_properties.PointProperty(crs='cartesian'))

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    an_object = AnotherLocalisableEntity(locations=
                                         [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))]).save()

    retrieved_object = AnotherLocalisableEntity.nodes.get(identifier=an_object.identifier)

    assert type(retrieved_object.locations) is list, "Array of Points definition failed."
    assert retrieved_object.locations == [neomodel.contrib.spatial_properties.NeomodelPoint((0.0,0.0)),
                                          neomodel.contrib.spatial_properties.NeomodelPoint((1.0,0.0))], \
        "Array of Points incorrect values."
github neo4j-contrib / neomodel / test / test_contrib / test_spatial_properties.py View on Github external
def test_default_value():
    """
    Tests that the default value passing mechanism works as expected with NeomodelPoint values.
    :return:
    """

    def get_some_point():
        return neomodel.contrib.spatial_properties.NeomodelPoint((random.random(),random.random()))

    class LocalisableEntity(neomodel.StructuredNode):
        """
        A very simple entity to try out the default value assignment.
        """
        identifier = neomodel.UniqueIdProperty()
        location = neomodel.contrib.spatial_properties.PointProperty(crs='cartesian', default=get_some_point)

    # Neo4j versions lower than 3.4.0 do not support Point. In that case, skip the test.
    check_and_skip_neo4j_least_version(340, 'This version does not support spatial data types.')

    # Save an object
    an_object = LocalisableEntity().save()
    coords = an_object.location.coords[0]
    # Retrieve it
    retrieved_object = LocalisableEntity.nodes.get(identifier=an_object.identifier)
    # Check against an independently created value
    assert retrieved_object.location == neomodel.contrib.spatial_properties.NeomodelPoint(coords), \
        "Default value assignment failed."
github grafit-io / grafit / backend / grafit / models.py View on Github external
cursor.execute(
        'REFRESH MATERIALIZED VIEW CONCURRENTLY grafit_search_word;')
    logger.info("finished updating search word")


class ArticleRel(StructuredRel):
    created_at = DateTimeProperty(
        default=lambda: datetime.now()
    )
    tf_idf = FloatProperty()
    hidden = BooleanProperty(default=False)
    label = StringProperty()


class GraphArticle(StructuredNode):
    uid = UniqueIdProperty()
    name = StringProperty()
    related = Relationship('GraphArticle', 'RELATED', model=ArticleRel)


class SearchResult(models.Model):
    id = models.BigIntegerField(primary_key=True)
    title = models.TextField()
    headline = models.TextField()
    rank = models.DecimalField(max_digits=19, decimal_places=2)

    class Meta:
        managed = False
        db_table = 'search_index'


class SearchWord(models.Model):
github mostafa / grest / examples / extended_app.py View on Github external
from neomodel import (IntegerProperty, RelationshipFrom, RelationshipTo,
                      StringProperty, StructuredNode, StructuredRel,
                      UniqueIdProperty)
from webargs import fields

from grest import GRest, global_config, models, utils


class PetInfo(StructuredRel, models.Relation):
    """Pet Information Model (for relationship)"""
    adopted_since = IntegerProperty()


class Pet(StructuredNode, models.Node):
    """Pet model"""
    pet_id = UniqueIdProperty()
    name = StringProperty()
    owner = RelationshipFrom("User", "HAS_PET")


class User(StructuredNode, models.Node):
    """User model"""
    __validation_rules__ = {
        "first_name": fields.Str(),
        "last_name": fields.Str(),
        "phone_number": fields.Str(required=True)
    }

    __filtered_fields__ = ["secret_field"]

    uid = UniqueIdProperty()
    first_name = StringProperty()
github mostafa / grest / grest / models.py View on Github external
model_types = [
            StringProperty, DateTimeProperty, DateProperty,
            EmailProperty, BooleanProperty, UniqueIdProperty,
            ArrayProperty, IntegerProperty, JSONProperty
        ]

        model_mapping = {
            IntegerProperty: fields.Int,
            StringProperty: fields.Str,
            BooleanProperty: fields.Bool,
            DateTimeProperty: fields.DateTime,
            DateProperty: fields.Date,
            EmailProperty: fields.Email,
            ArrayProperty: fields.List,
            JSONProperty: fields.Dict,
            UniqueIdProperty: fields.UUID
        }

        name = 0
        value = 1

        for field in self.defined_properties().items():
            if field[name] not in self.__validation_rules__:
                if type(field[value]) in model_types:
                    if isinstance(field[value], ArrayProperty):
                        if field[value].unique_index:
                            # what it contains: Array of *String*
                            container = model_mapping[
                                type(field[value].unique_index)]
                        else:
                            # defaults to Raw for untyped ArrayProperty
                            container = fields.Raw
github mostafa / grest / examples / extended_app.py View on Github external
pet_id = UniqueIdProperty()
    name = StringProperty()
    owner = RelationshipFrom("User", "HAS_PET")


class User(StructuredNode, models.Node):
    """User model"""
    __validation_rules__ = {
        "first_name": fields.Str(),
        "last_name": fields.Str(),
        "phone_number": fields.Str(required=True)
    }

    __filtered_fields__ = ["secret_field"]

    uid = UniqueIdProperty()
    first_name = StringProperty()
    last_name = StringProperty()
    phone_number = StringProperty(unique_index=True, required=True)

    secret_field = StringProperty(default="secret", required=False)

    pets = RelationshipTo(Pet, "HAS_PET", model=PetInfo)


class UsersView(GRest):
    """User's View (/users)"""
    __model__ = {"primary": User,
                 "secondary": {
                     "pets": Pet
                 }}
    __selection_field__ = {"primary": "uid",