~ubuntu-branches/debian/squeeze/python-django/squeeze

« back to all changes in this revision

Viewing changes to tests/modeltests/mutually_referential/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb, Chris Lamb, David Spreen, Sandro Tosi
  • Date: 2008-11-19 21:31:00 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081119213100-gp0lqhxl1qxa6dgl
Tags: 1.0.2-1
[ Chris Lamb ]
* New upstream bugfix release. Closes: #505783
* Add myself to Uploaders with ACK from Brett.

[ David Spreen ]
* Remove python-pysqlite2 from Recommends because Python 2.5 includes
  sqlite library used by Django. Closes: 497886

[ Sandro Tosi ]
* debian/control
  - switch Vcs-Browser field to viewsvn

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
24. Mutually referential many-to-one relationships
3
 
 
4
 
Strings can be used instead of model literals to set up "lazy" relations.
5
 
"""
6
 
 
7
 
from django.db.models import *
8
 
 
9
 
class Parent(Model):
10
 
    name = CharField(max_length=100)
11
 
    
12
 
    # Use a simple string for forward declarations.
13
 
    bestchild = ForeignKey("Child", null=True, related_name="favoured_by")
14
 
 
15
 
class Child(Model):
16
 
    name = CharField(max_length=100)
17
 
    
18
 
    # You can also explicitally specify the related app.
19
 
    parent = ForeignKey("mutually_referential.Parent")
20
 
 
21
 
__test__ = {'API_TESTS':"""
22
 
# Create a Parent
23
 
>>> q = Parent(name='Elizabeth')
24
 
>>> q.save()
25
 
 
26
 
# Create some children
27
 
>>> c = q.child_set.create(name='Charles')
28
 
>>> e = q.child_set.create(name='Edward')
29
 
 
30
 
# Set the best child
31
 
>>> q.bestchild = c
32
 
>>> q.save()
33
 
 
34
 
>>> q.delete()
35
 
 
36
 
"""}
 
 
b'\\ No newline at end of file'