PageRenderTime 72ms CodeModel.GetById 68ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/reverse_lookup/models.py

https://code.google.com/p/mango-py/
Python | 28 lines | 16 code | 7 blank | 5 comment | 0 complexity | 8e6a712478c90417ffd1bfbb91f6a36d MD5 | raw file
 1"""
 225. Reverse lookups
 3
 4This demonstrates the reverse lookup features of the database API.
 5"""
 6
 7from django.db import models
 8
 9class User(models.Model):
10    name = models.CharField(max_length=200)
11
12    def __unicode__(self):
13        return self.name
14
15class Poll(models.Model):
16    question = models.CharField(max_length=200)
17    creator = models.ForeignKey(User)
18
19    def __unicode__(self):
20        return self.question
21
22class Choice(models.Model):
23    name = models.CharField(max_length=100)
24    poll = models.ForeignKey(Poll, related_name="poll_choice")
25    related_poll = models.ForeignKey(Poll, related_name="related_choice")
26
27    def __unicode__(self):
28        return self.name