Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFatih Erarslan
Courses Plus Student 288 PointsDjango - Multi-step Survey Form (Wizard) using a single table
Dear all,
I am a newbie. Please forgive my ignorance if this sounds very stupid. I am building a survey tool using Django to collect data from user for a research project for a non-profit organization. I have users, (Django built-in) Questions and Survey tables. Survey model these classes:
class Competence(models.Model):
competence_name = models.CharField(max_length=24)
class Level(models.Model):
level_name = models.CharField(max_length=24)
class Questions(models.Model):
competence = models.ForeignKey(Competence, on_delete=models.CASCADE)
level = models.ForeignKey(Level, on_delete=models.CASCADE)
question = models.TextField()
class Survey(models.Model):
question = models.ForeignKey(Questions, on_delete=models.CASCADE)
author = models.ForeignKey(User, on_delete=models.CASCADE)
answer = models.TextField(max_length=200, editable=True)
started_at = models.DateTimeField(default=timezone.now)
is_complete = models.BooleanField()
There will be multiple records of the same survey for one user.. So, for convenience, I would like the users answer one question at a time, and click next to answer the following.. I am not sure about which package to use, can formtools WizardView with Sessions could be a solution or should I use Django formsets? What would you recommend? Is there any other approach I can use here?
I will truly appreciate your help.
Thank you in advance.
1 Answer
Henrik Christensen
Python Web Development Techdegree Student 38,322 PointsNot sure how you would do this in Django, but have you considered using JavaScript to hide all but one field? :-)
Something like:
# display 1st field + button (should not be a submit button)
# hide this field when it has been filled and button clicked
# then display the next field + button (should not be a submit button)
# keep repeating this process
# When it's time for the last field:
# hide all fields but the last field + a submit button
# when the field has been filled and submit button clicked
# then send all data collected to the server