forked from CGM_Public/pretix_original
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:
committed by
Raphael Michel
parent
68967fbfda
commit
3583dde1db
20
src/pretix/base/migrations/0032_question_position.py
Normal file
20
src/pretix/base/migrations/0032_question_position.py
Normal 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),
|
||||
),
|
||||
]
|
||||
19
src/pretix/base/migrations/0033_auto_20160821_2222.py
Normal file
19
src/pretix/base/migrations/0033_auto_20160821_2222.py
Normal 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'},
|
||||
),
|
||||
]
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user