I am using Parse to build my database.
I have two tables: Article
& Comment
. Where Article
has one or many Comments
I am using Parse Resful API [ParsePy][1]
to add items
from parse_rest.datatypes import Object
class Article(Object):
pass
class Comment(Object):
pass
articleItem = Article(title='Test', author='John Doe')
articleItem.save() # we have to save it before it can be referenced
I don't know how to achieve this 1:N relationship, Can anyone show a way to make this:
from parse_rest.datatypes import Object
class Article(Object):
pass
class Comment(Object):
pass
articleItem = Article(title='Test', author='John Doe')
# for example, you get data from json
comments = []
for data in incoming_json['comments']:
# Don't know why, but this cannot working [Comments(**data).save() for data in incoming_json['comments]]
comment = Comments(**data)
comment.save()
comments.append(comment)
articleItem.comments = comments
articleItem.save() # we have to save it before it can be referenced
If you get query, you will receive:
[<Comments:v6PvbsPbQT>, <Comments:V5JpqPRuS6>, <Comments:HNocXqmUeJ>,]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.