Skip to content
This repository was archived by the owner on Jun 15, 2020. It is now read-only.
This repository was archived by the owner on Jun 15, 2020. It is now read-only.

Remove Extra Question Models #54

Open
@andrewkchan

Description

@andrewkchan

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions