Skip to content
pembeci edited this page Oct 31, 2017 · 3 revisions
  • Finish Part 3 of "Writing your first Django app" official tutorial. You can pull the latest from this repository and continue from there if you couldn't have finished the first two parts in the previous lab.

  • Add a new field to your Question model to record the category of a poll:

    category = models.CharField(max_length=200, default="")

Show category of polls in the index page and also in the poll details page by modifying your templates. Remember that you need to run the migration related manage.py commands after you made this change to your model.

  • If you have time, add a dynamic page which will only list polls for a given category. You may assume that URL will be in the form of: polls/category/xyz where xyz is some category. You may pull from the database Question rows which has this category with a code like this:
    Question.objects.filter(category=q_category)

Assuming q_category is a variable holding the category in question and category is the field name you used in your model definition (i.e. as in above code). If the category specified in the URL doesn't have any related polls in the DB show an appropriate message. Modify your templates such that wherever you are printing a category name, convert them into a link to the related category page.

Clone this wiki locally