from django.db import models
from ordered_model.models import OrderedModel, OrderedModelBase


class Item(OrderedModel):
    name = models.CharField(max_length=100)


class Question(models.Model):
    pass


class TestUser(models.Model):
    pass


class Answer(OrderedModel):
    question = models.ForeignKey(Question, on_delete=models.CASCADE, related_name='answers')
    user = models.ForeignKey(TestUser, on_delete=models.CASCADE, related_name='answers')
    order_with_respect_to = ('question', 'user')

    class Meta:
        ordering = ('question', 'user', 'order')

    def __unicode__(self):
        return u"Answer #{0:d} of question #{1:d} for user #{2:d}".format(self.order, self.question_id, self.user_id)


class CustomItem(OrderedModel):
    id = models.CharField(max_length=100, primary_key=True)
    name = models.CharField(max_length=100)
    modified = models.DateTimeField(null=True, blank=True)


class CustomOrderFieldModel(OrderedModelBase):
    sort_order = models.PositiveIntegerField(editable=False, db_index=True)
    name = models.CharField(max_length=100)
    order_field_name = 'sort_order'

    class Meta:
        ordering = ('sort_order',)


class Topping(models.Model):
    name = models.CharField(max_length=100)


class Pizza(models.Model):
    name = models.CharField(max_length=100)
    toppings = models.ManyToManyField(Topping, through='PizzaToppingsThroughModel')


class PizzaToppingsThroughModel(OrderedModel):
    pizza = models.ForeignKey(Pizza, on_delete=models.CASCADE)
    topping = models.ForeignKey(Topping, on_delete=models.CASCADE)
    order_with_respect_to = 'pizza'

    class Meta:
        ordering = ('pizza', 'order')

class BaseQuestion(OrderedModel):
    order_class_path = __module__ + '.BaseQuestion'
    question = models.TextField(max_length=100)
    class Meta:
        ordering = ('order',)

class MultipleChoiceQuestion(BaseQuestion):
    good_answer = models.TextField(max_length=100)
    wrong_answer1 = models.TextField(max_length=100)
    wrong_answer2 = models.TextField(max_length=100)
    wrong_answer3 = models.TextField(max_length=100)

class OpenQuestion(BaseQuestion):
    answer = models.TextField(max_length=100)

[((132, 164), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (148, 164), False, 'from django.db import models\n'), ((292, 369), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Question'], {'on_delete': 'models.CASCADE', 'related_name': '"""answers"""'}), "(Question, on_delete=models.CASCADE, related_name='answers')\n", (309, 369), False, 'from django.db import models\n'), ((381, 458), 'django.db.models.ForeignKey', 'models.ForeignKey', (['TestUser'], {'on_delete': 'models.CASCADE', 'related_name': '"""answers"""'}), "(TestUser, on_delete=models.CASCADE, related_name='answers')\n", (398, 458), False, 'from django.db import models\n'), ((763, 813), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)', 'primary_key': '(True)'}), '(max_length=100, primary_key=True)\n', (779, 813), False, 'from django.db import models\n'), ((825, 857), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (841, 857), False, 'from django.db import models\n'), ((873, 916), 'django.db.models.DateTimeField', 'models.DateTimeField', ([], {'null': '(True)', 'blank': '(True)'}), '(null=True, blank=True)\n', (893, 916), False, 'from django.db import models\n'), ((983, 1041), 'django.db.models.PositiveIntegerField', 'models.PositiveIntegerField', ([], {'editable': '(False)', 'db_index': '(True)'}), '(editable=False, db_index=True)\n', (1010, 1041), False, 'from django.db import models\n'), ((1053, 1085), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1069, 1085), False, 'from django.db import models\n'), ((1216, 1248), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1232, 1248), False, 'from django.db import models\n'), ((1289, 1321), 'django.db.models.CharField', 'models.CharField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1305, 1321), False, 'from django.db import models\n'), ((1337, 1405), 'django.db.models.ManyToManyField', 'models.ManyToManyField', (['Topping'], {'through': '"""PizzaToppingsThroughModel"""'}), "(Topping, through='PizzaToppingsThroughModel')\n", (1359, 1405), False, 'from django.db import models\n'), ((1467, 1517), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Pizza'], {'on_delete': 'models.CASCADE'}), '(Pizza, on_delete=models.CASCADE)\n', (1484, 1517), False, 'from django.db import models\n'), ((1532, 1584), 'django.db.models.ForeignKey', 'models.ForeignKey', (['Topping'], {'on_delete': 'models.CASCADE'}), '(Topping, on_delete=models.CASCADE)\n', (1549, 1584), False, 'from django.db import models\n'), ((1778, 1810), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1794, 1810), False, 'from django.db import models\n'), ((1920, 1952), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1936, 1952), False, 'from django.db import models\n'), ((1973, 2005), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (1989, 2005), False, 'from django.db import models\n'), ((2026, 2058), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (2042, 2058), False, 'from django.db import models\n'), ((2079, 2111), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (2095, 2111), False, 'from django.db import models\n'), ((2160, 2192), 'django.db.models.TextField', 'models.TextField', ([], {'max_length': '(100)'}), '(max_length=100)\n', (2176, 2192), False, 'from django.db import models\n')]