| 1 |
from django.db import models |
| 2 |
|
| 3 |
|
| 4 |
class Poll(models.Model): |
| 5 |
question = models.CharField(max_length=200) |
| 6 |
|
| 7 |
|
| 8 |
class Choice(models.Model): |
| 9 |
poll = models.ForeignKey(Poll, models.CASCADE) |
| 10 |
choice = models.CharField(max_length=200) |
| 11 |
|
| 12 |
|
| 13 |
# A set of models with an inner one pointing to two outer ones. |
| 14 |
|
| 15 |
|
| 16 |
class OuterA(models.Model): |
| 17 |
pass |
| 18 |
|
| 19 |
|
| 20 |
class OuterB(models.Model): |
| 21 |
data = models.CharField(max_length=10) |
| 22 |
|
| 23 |
|
| 24 |
class Inner(models.Model): |
| 25 |
first = models.ForeignKey(OuterA, models.CASCADE) |
| 26 |
# second would clash with the __second lookup. |
| 27 |
third = models.ForeignKey(OuterB, models.SET_NULL, null=True) |