2012-06-07 18:08:47 +02:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2006-10-14 04:48:05 +02:00
|
|
|
from django.db import models
|
2012-08-12 12:32:08 +02:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2006-10-14 04:48:05 +02:00
|
|
|
|
2011-10-13 23:34:56 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2006-10-14 04:48:05 +02:00
|
|
|
class Poll(models.Model):
|
2007-08-05 07:14:46 +02:00
|
|
|
question = models.CharField(max_length=200)
|
2006-10-14 04:48:05 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "Q: %s " % self.question
|
2006-10-14 04:48:05 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
@python_2_unicode_compatible
|
2006-10-14 04:48:05 +02:00
|
|
|
class Choice(models.Model):
|
|
|
|
poll = models.ForeignKey(Poll)
|
2007-08-05 07:14:46 +02:00
|
|
|
choice = models.CharField(max_length=200)
|
2006-10-14 04:48:05 +02:00
|
|
|
|
2012-08-12 12:32:08 +02:00
|
|
|
def __str__(self):
|
2012-06-07 18:08:47 +02:00
|
|
|
return "Choice: %s in poll %s" % (self.choice, self.poll)
|
2006-10-14 04:48:05 +02:00
|
|
|
|
2009-03-06 03:02:09 +01:00
|
|
|
# A set of models with an inner one pointing to two outer ones.
|
|
|
|
class OuterA(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class OuterB(models.Model):
|
|
|
|
data = models.CharField(max_length=10)
|
|
|
|
|
|
|
|
class Inner(models.Model):
|
|
|
|
first = models.ForeignKey(OuterA)
|
2013-02-10 16:15:49 +01:00
|
|
|
# second would clash with the __second lookup.
|
|
|
|
third = models.ForeignKey(OuterB, null=True)
|