codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

A following models with django neomodel


By : , Category : python

Hi author of neomodel here.

There is no need to save in the follow_person method. Which version of neomodel are you using? The following code worked for me:

class UserNode(StructuredNode):                                                                                                                                                                        
    user_id = IntegerProperty(required=True, index=True)
    follow = RelationshipTo('UserNode', 'FOLLOW')

    def get_followers(self):
        results, metadata = self.cypher("START a=node({self}) MATCH a<-[:FOLLOW]-(b) RETURN b")
        return [self.__class__.inflate(row[0]) for row in results]

    def get_following(self):
        results, metadata = self.cypher("START a=node({self}) MATCH b-[:FOLLOW]->(a) RETURN b")
        return [self.__class__.inflate(row[0]) for row in results]

    def follow_person(self, user_id):
        followed_user = self.index.get(user_id=user_id)
        self.follow.connect(followed_user, {'time': str(datetime.datetime.utcnow())})

u1 = UserNode(user_id=1).save()
u2 = UserNode(user_id=2).save()

u1.follow_person(2)
u2.follow_person(1)
print "User 1 follows {}".format(u1.get_following())
print "User 1's followers {}".format(u1.get_followers())

You may also want to consider defining two separate relationship managers for out coming and incoming, this means you don't need to write cypher queries:

class UserNode(StructuredNode):
    user_id = IntegerProperty(required=True, index=True)
    following = RelationshipTo('UserNode', 'FOLLOW')
    followers = RelationshipFrom('UserNode', 'FOLLOW')

    def follow_person(self, user_id):
        followed_user = self.index.get(user_id=user_id)
        self.follow.connect(followed_user, {'time': str(datetime.datetime.utcnow())})

print "User 1 follows {}".format(u1.following.all())
print "User 1's followers {}".format(u1.followers.all())

Hope this helps! Feel free to drop me an email if you any more issues.

ReLated :

If the settings are meant to be opaque (for example, you don't need to filter based on particular values in your dicts) you can just store these as regular Python objects using something like django-picklefield.

>>> from picklefield.fields import PickledObjectField
... class SomeObject(models.Model): 
...     args = PickledObjectField()
>>> obj = SomeObject()
>>> obj.args = ['fancy', {'objects': 'inside'}]
>>> obj.save()

You need to write you convertor(updater) into the migration file (in forward case). And if you want you can implement backward case

Example here http://concentricsky.com/blog/2014/jan/data-migrations-south-and-django

This seems to be a problem with that library. I suggest implementing you own logical delete (which is rather easy with a LogicalDeleteManager and a LogicalDeleteModel) or using a lower version of django

As a simplistic example:

class MyLogicalDeleteManager(models.Manager):
    def __init__(self, show_deleted_objects=False)
        super(MyLogicalDeleteManager, self).__init__()
        self.show_deleted_objects = show_deleted_objects

    def get_queryset(self):
         qs = super(MyLogicalDeleteManager, self).get_queryset()
         return qs.filter(deleted=self.show_deleted_objects)

class MyLogicalDeleteModel(models.Model):
    deleted = models.BooleanField(default=False)
    objects = MyLogicalDeleteManager(False)
    deleted_objects = MyLogicalDeleteManager(True)
    all_objects = models.Manager()

    def delete(self):
        # Maybe check FK constraints with self._meta.get_all_related_objects()
        self.deleted = True
        self.save()

Switch the order of these statements, so that your QueryJob is created first, then your PropertyQuery models are created:

def save(self, *args, **kwargs):
    super(QueryJob, self).save(*args, **kwargs)
    self.createqueries()

In your createqueries() method, you can refer to self when you need to create a link. Do not create a link to the primary key directly as this won't work - you don't realize its not working because you have a blank except clause that is catching the exceptions raised:

def createqueries(self):
    #json_data = json.loads(self.Json)
    print self.Json
    for each in self.Json:
        Street = each.get(self.street_column)
        State = each.get(self.state_column)
        Suburb = each.get(self.suburb_column)
        Postcode = each.get(self.postcode_column)
        q = PropertyQuery(street_address = Street,
                          state=State,
                          suburb = Suburb,
                          postcode=Postcode,
                          queryID=self)
        q.save()
Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .