Skip to content

Commit

Permalink
Merge pull request #14 from bencrealc/mrespuesta
Browse files Browse the repository at this point in the history
Pregunta Si/No/NS
  • Loading branch information
bencrealc authored Jan 5, 2022
2 parents acb0a19 + 50e9102 commit 09b7225
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions decide/voting/migrations/0009_question_ynns_question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0 on 2022-01-05 12:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('voting', '0008_auto_20220104_1653'),
]

operations = [
migrations.AddField(
model_name='question',
name='YNNS_question',
field=models.BooleanField(default=False, help_text='Check the box to create a question of Yes, No or NS/NC', verbose_name='Answers Yes, No, NS/NC'),
),
]
14 changes: 14 additions & 0 deletions decide/voting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def clean(self):
def __str__(self):
return self.desc

YNNS_question = models.BooleanField(default=False,verbose_name="Answers Yes, No, NS/NC", help_text="Check the box to create a question of Yes, No or NS/NC")
def __str__(self):
return self.desc


@receiver(post_save, sender=Question)
def check_question(sender, instance, **kwargs):
Expand All @@ -27,6 +31,16 @@ def check_question(sender, instance, **kwargs):
option2 = QuestionOption(question=instance, number=2, option="No")
option2.save()

@receiver(post_save, sender=Question)
def check_question(sender, instance, **kwargs):
if instance.YNNS_question==True and instance.options.all().count()==0:
option1 = QuestionOption(question=instance, number=1, option="Si")
option1.save()
option2 = QuestionOption(question=instance, number=2, option="No")
option2.save()
option2 = QuestionOption(question=instance, number=3, option="NS/NC")
option2.save()


class QuestionOption(models.Model):
question = models.ForeignKey(Question, related_name='options', on_delete=models.CASCADE)
Expand Down

0 comments on commit 09b7225

Please sign in to comment.