Fix #202 -- Allow the manual ordering of questions

* Allow the manual ordering of questions
Update Unit Tests
Fix some typos

* Add migrations

* Minor notation change
This commit is contained in:
Enrique Saez
2016-08-29 18:36:56 +02:00
committed by Raphael Michel
parent 68967fbfda
commit 3583dde1db
8 changed files with 119 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-21 19:27
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0031_auto_20160816_0648'),
]
operations = [
migrations.AddField(
model_name='question',
name='position',
field=models.IntegerField(default=0),
),
]

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-08-21 22:22
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0032_question_position'),
]
operations = [
migrations.AlterModelOptions(
name='question',
options={'ordering': ('position', 'id'), 'verbose_name': 'Question', 'verbose_name_plural': 'Questions'},
),
]

View File

@@ -386,10 +386,14 @@ class Question(LoggedModel):
blank=True,
help_text=_('This question will be asked to buyers of the selected products')
)
position = models.IntegerField(
default=0
)
class Meta:
verbose_name = _("Question")
verbose_name_plural = _("Questions")
ordering = ('position', 'id')
def __str__(self):
return str(self.question)
@@ -404,6 +408,13 @@ class Question(LoggedModel):
if self.event:
self.event.get_cache().clear()
@property
def sortkey(self):
return self.position, self.id
def __lt__(self, other) -> bool:
return self.sortkey < other.sortkey
class QuestionOption(models.Model):
question = models.ForeignKey('Question', related_name='options')