Skip to content

Commit

Permalink
CREAR TIPO POSTPROCESADO EN QUESTION
Browse files Browse the repository at this point in the history
Se ha añadido un nuevo atributo en el model Question que indica el tipo de
postprocesado que se utilizará para hacer el recuento de la votación.
Inicialmente añadimos 3 tipos: DHont, Borda, SaintLaigue. Serán los
tres que implementarán el equipo encargado del modulo postproc.
Se actualizará en caso de que sea necesario.

En el views, se añade el atributo postproc_type creado en el método post para
que pueda ser elegido en el formulación de creación de la pregunta.
  • Loading branch information
luctorgom committed Dec 18, 2021
1 parent c514697 commit c9233b7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
18 changes: 18 additions & 0 deletions decide/voting/migrations/0004_question_postproc_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0 on 2021-12-18 18:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('voting', '0003_auto_20180605_0842'),
]

operations = [
migrations.AddField(
model_name='question',
name='postproc_type',
field=models.IntegerField(choices=[(1, 'Dhont'), (2, 'Borda'), (3, 'SaintLague')], default=1),
),
]
18 changes: 18 additions & 0 deletions decide/voting/migrations/0005_auto_20211218_1835.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0 on 2021-12-18 18:35

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('voting', '0004_question_postproc_type'),
]

operations = [
migrations.AlterField(
model_name='question',
name='postproc_type',
field=models.IntegerField(choices=[(2, 'Borda'), (1, 'Dhont'), (3, 'SaintLague')], default=1),
),
]
1 change: 1 addition & 0 deletions decide/voting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class Question(models.Model):
desc = models.TextField()
postproc_type=models.IntegerField(choices={(1,'Dhont'),(2,'Borda'),(3,'SaintLague')},default=1)

def __str__(self):
return self.desc
Expand Down
3 changes: 2 additions & 1 deletion decide/voting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def post(self, request, *args, **kwargs):
if not data in request.data:
return Response({}, status=status.HTTP_400_BAD_REQUEST)

question = Question(desc=request.data.get('question'))
question = Question(desc=request.data.get('question'),
postproc_type=request.data.get('question'))
question.save()
for idx, q_opt in enumerate(request.data.get('question_opt')):
opt = QuestionOption(question=question, option=q_opt, number=idx)
Expand Down

0 comments on commit c9233b7

Please sign in to comment.