title: Report Lab Printing Values From Forms Rather Than Database
body: <p>I have a website where users must complete a large questionnaire spread over four webpages (and four forms) and after completing the questionnaire reportlab generates a pdf of their answers.</p>
  
  <p>Here is my working code</p>
  
  <p>utils.py</p>
  
  <pre><code>def generate_pdf(request):
      # get user
      user = request.user
  
      # get users age
      born = request.user.personalinformation.dob
      age = user_utils.get_age(born)
  
      doc = SimpleDocTemplate(settings.MEDIA_ROOT+'\pdf_templates\\enrolment_form_%s.pdf' %user.id)
      styles = getSampleStyleSheet()
      enrolment_form = [Spacer(1,2*inch)]
      style = styles["Normal"]
  
      page_contents = [
      ("Name: %s %s" % (user.personalinformation.first_name, user.personalinformation.surname)),
      ("Gender: %s" % (user.personalinformation.gender)),
      ("Age: %s" % (age))
      ]
  
      for sections in page_contents:
          p = Paragraph(sections, style)
          enrolment_form.append(p)
          enrolment_form.append(Spacer(1,0.2*inch))
  
      doc.build(enrolment_form)
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>class PersonalInformation(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)
  
      GENDERS = (
          ('M', 'Male'),
          ('F', 'Female'),
      )
  
      first_name = models.CharField(max_length=200, default='')
      surname = models.CharField(max_length=200, default='')
      gender = models.CharField(max_length=1, choices=GENDERS)
      dob = models.DateTimeField('Date of birth (mm/dd/yyyy)', null=True, default=now)
  
      def __str__(self):
          return f'{self.user.username}'
  </code></pre>
  
  <p>(I also have a form.py but dont think its worth including)</p>
  
  <p>This works fine, except for fields like 'gender'. Because its getting the values its printing on the pdf from user.personalinformation from the database, instead of printing 'Gender: Male', its printing 'Gender: M'. While this example seems trivial, there are many more fields with key/value pairs and booleans which make no sense printed this way.</p>
  
  <p>How could I print the values as they are displayed in the form and to the user, rather than printing the values saved in the database?</p>
  
  <p>Thank you.</p>