2006-05-02 09:31:56 +08:00
|
|
|
"""
|
2014-09-24 13:13:13 +08:00
|
|
|
Reverse lookups
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
This demonstrates the reverse lookup features of the database API.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class User(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=200)
|
2006-06-04 08:23:51 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class Poll(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
question = models.CharField(max_length=200)
|
2015-07-22 22:43:21 +08:00
|
|
|
creator = models.ForeignKey(User, models.CASCADE)
|
2006-06-04 08:23:51 +08:00
|
|
|
|
2013-11-03 05:34:05 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class Choice(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
name = models.CharField(max_length=100)
|
2015-07-22 22:43:21 +08:00
|
|
|
poll = models.ForeignKey(Poll, models.CASCADE, related_name="poll_choice")
|
|
|
|
related_poll = models.ForeignKey(
|
|
|
|
Poll, models.CASCADE, related_name="related_choice"
|
|
|
|
)
|