Remove Extra Question Models #54
Description
The subclasses of Question
that I created earlier for convenience (Paragraph
, Checkbox
, Radiobutton
, Dropdown
) were in retrospect a big mistake. Here's why:
If we want to change the question type of an existing question, we can just change the string attribute Question.question_type
, but that won't make the question show up in the sublass's queries. Consider the following code:
>>> from portal.models import Radiobutton, Paragraph
>>> p = Paragraph.create("Why CodeBase?")
>>> p.save()
>>> Paragraph.objects.all()
<QuerySet [<Paragraph: "Why CodeBase?">]>
>>> p.question_type = Radiobutton.__name__
>>> p.save()
>>> Radiobutton.objects.all()
<QuerySet []>
>>> Paragraph.objects.all()
<QuerySet [<Paragraph: "Why CodeBase?">]>
The above is a bit of a contrived example, but the point is that because Django creates separate database tables for each subclass, the queries using the convenience classes are fundamentally broken. Luckily we don't have a huge amount of code that relies on them, but we should delete the convenience subclasses as soon as possible and change all of our code to use the base class Question
instead.