mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
feat(people): Make relationship questions / choices sortable
resolve #7
This commit is contained in:
@@ -16,16 +16,22 @@ class PersonAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(models.RelationshipQuestion)
|
||||
class RelationshipQuestionAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
@admin.register(models.RelationshipQuestionChoice)
|
||||
class RelationshipQuestionChoiceAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class RelationshipQuestionChoiceInline(admin.TabularInline):
|
||||
model = models.RelationshipQuestionChoice
|
||||
|
||||
|
||||
@admin.register(models.RelationshipQuestion)
|
||||
class RelationshipQuestionAdmin(admin.ModelAdmin):
|
||||
inlines = [
|
||||
RelationshipQuestionChoiceInline,
|
||||
]
|
||||
|
||||
|
||||
@admin.register(models.Relationship)
|
||||
class RelationshipAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
31
people/migrations/0006_relationship_questions_order.py
Normal file
31
people/migrations/0006_relationship_questions_order.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Generated by Django 2.2.10 on 2020-02-20 10:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('people', '0005_user_one_person'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='relationshipquestion',
|
||||
options={'ordering': ['order', 'text']},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='relationshipquestionchoice',
|
||||
options={'ordering': ['order', 'text']},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='relationshipquestion',
|
||||
name='order',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='relationshipquestionchoice',
|
||||
name='order',
|
||||
field=models.SmallIntegerField(default=0),
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,5 @@
|
||||
import typing
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
@@ -54,6 +56,12 @@ class RelationshipQuestion(models.Model):
|
||||
"""
|
||||
Question which may be asked about a relationship.
|
||||
"""
|
||||
class Meta:
|
||||
ordering = [
|
||||
'order',
|
||||
'text',
|
||||
]
|
||||
|
||||
#: Version number of this question - to allow modification without invalidating existing data
|
||||
version = models.PositiveSmallIntegerField(default=1,
|
||||
blank=False, null=False)
|
||||
@@ -62,6 +70,19 @@ class RelationshipQuestion(models.Model):
|
||||
text = models.CharField(max_length=1023,
|
||||
blank=False, null=False)
|
||||
|
||||
#: Position of this question in the list
|
||||
order = models.SmallIntegerField(default=0,
|
||||
blank=False, null=False)
|
||||
|
||||
@property
|
||||
def choices(self) -> typing.List[typing.List[str]]:
|
||||
"""
|
||||
Convert the :class:`RelationshipQuestionChoices` for this question into Django choices.
|
||||
"""
|
||||
return [
|
||||
[choice.pk, str(choice)] for choice in self.answers.all()
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.text
|
||||
|
||||
@@ -75,6 +96,10 @@ class RelationshipQuestionChoice(models.Model):
|
||||
models.UniqueConstraint(fields=['question', 'text'],
|
||||
name='unique_question_answer')
|
||||
]
|
||||
ordering = [
|
||||
'order',
|
||||
'text',
|
||||
]
|
||||
|
||||
#: Question to which this answer belongs
|
||||
question = models.ForeignKey(RelationshipQuestion, related_name='answers',
|
||||
@@ -85,6 +110,10 @@ class RelationshipQuestionChoice(models.Model):
|
||||
text = models.CharField(max_length=1023,
|
||||
blank=False, null=False)
|
||||
|
||||
#: Position of this answer in the list
|
||||
order = models.SmallIntegerField(default=0,
|
||||
blank=False, null=False)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user