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

Remove Extra Question Models #54

Open
andrewkchan opened this issue Jan 6, 2018 · 0 comments
Open

Remove Extra Question Models #54

andrewkchan opened this issue Jan 6, 2018 · 0 comments
Assignees
Labels

Comments

@andrewkchan
Copy link
Contributor

andrewkchan commented Jan 6, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants