#1 by prm74
Hi, I have a simple radio button survey question, with 4 options. I use random and shuffle to change the order of the options, and on the HTML simply say {{ formfields.}} However is there a way I can record exactly in which order a participant saw those 4 radio buttons? Below I attach my code. selfprofile = models.IntegerField(label="Which of the following profiles best match you?", widget=widgets.RadioSelect, choices=[[1, 'LL'], [2, 'LH'], [3, 'HL'], [4, 'HH']], ) # FUNCTIONS def selfprofile_choices(player): import random choices=[[1, 'LL'], [2, 'LH'], [3, 'HL'], [4, 'HH']] random.shuffle(choices) return choices
#2 by BonnEconLab (edited )
The simplest solution is to include the following: class Player(BasePlayer): selfprofile_order = models.StringField(initial="") def selfprofile_choices(player): import random choices = [[1, 'LL'], [2, 'LH'], [3, 'HL'], [4, 'HH']] random.shuffle(choices) player.selfprofile_order = str(choices) return choices If you would prefer something that will be easier to analyze later on, then you could also do def selfprofile_choices(player): import random choices = [[1, 'LL'], [2, 'LH'], [3, 'HL'], [4, 'HH']] random.shuffle(choices) choices_order = [c[0] for c in choices] # Record order of the IDs player.selfprofile_order = str(choices_order) return choices or def selfprofile_choices(player): import random choices = [[1, 'LL'], [2, 'LH'], [3, 'HL'], [4, 'HH']] random.shuffle(choices) choices_order = [c[1] for c in choices] # Record order of the strings player.selfprofile_order = str(choices_order) return choices