Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ParsePy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ParsePy
Commits
ce033eab
Commit
ce033eab
authored
Dec 04, 2015
by
johnk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added documentation for Relations
parent
9d8ae000
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
README.mkd
+49
-0
No files found.
README.mkd
View file @
ce033eab
...
...
@@ -370,6 +370,55 @@ for post in posts_by_joe:
**TODO**
: Slicing of Querysets
Relations
---------
You can associate multiple objects to a single object
by using a Relation.
You then query against this subset of objects.
~~~
~~ {python}
game = Game(name="3-way Battle")
game.save()
score1 = GameScore(player_name='Ronald', score=100)
score2 = GameScore(player_name='Rebecca', score=140)
score3 = GameScore(player_name='Sara', score=190)
relation = game.relation('scores')
relation.add([score1, score2, score3])
~~~
~~
A Game gets added, three GameScores get added, and three relations
are created associating the scores with the game.
To retreive the related scores for a game, you use query() to get a
Queryset for the relation.
~~~
~~ {python}
scores = relation.query()
for gamescore in scores:
print gamescore.player_name, gamescore.score
~~~
~~
The Queryset can be manipulated like any Queryset.
The query is limited to the objects previously added to the
relation.
~~~
~~ {python}
scores = relation.query().order_by('score', descending=True)
for gamescore in scores:
print gamescore.player_name, gamescore.score
~~~
~~
To remove objects from a relation, you use remove(). This example
removes all the related objects.
~~~
~~ {python}
scores = relation.query()
for gamescore in scores:
relation.remove(gamescore)
~~~
~~
Users
-----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment