I'm still very new to programming and I'm worried that I'm barking up the wrong tree. I'm trying to write a multiple choice quiz app. I have 5000 different words and their definitions. I've made two dictionaries. One with the word definitions and one with 4 choice - 1 of which is the correct answer.
I've already got written the model classes. I've also have generated a txt file that I can copy into the django shell. This links a definition to the 4 possible answers, and assigns True to the correct one. But since there are many words, I want to automate the entry into the django shell. Can I do that?
First I tried writing a batch file but that doesn't work once the shell is opened.
I've also tried reading this:
https://docs.djangoproject.com/en/1.9/howto/custom-management-commands/
I produced a complete monstrosity of code that I knew wouldn't work! I don't quite understand what's going on in the above link. Or even if it suits my purposes.
Anyway, here's the text I generated. I can copy this, line by line, into the django shell. It will do what I want (or at least what I think I want - I may be going about this the wrong way for all I know!) But obviously I want to do it with one click rather than copy and paste 30000 lines of text.
from quiz.models import Question, Class
q1=Question(question_text="used to refer to somebody/something that has already been mentioned or is easily understood,")
q1.save()
q1.choice_set.create(choice_text='the', rorwrong=True)
q1.choice_set.create(choice_text='be', rorwrong=False)
q1.choice_set.create(choice_text='of', rorwrong=False)
q1.choice_set.create(choice_text='a', rorwrong=False)
....
q1849=Question(question_text="to be frightened of somebody/something or frightened of doing something,")
q1849.save()
q1849.choice_set.create(choice_text='detail', rorwrong=False)
q1849.choice_set.create(choice_text='fear', rorwrong=True)
q1849.choice_set.create(choice_text='beautiful', rorwrong=False)
q1849.choice_set.create(choice_text='institution', rorwrong=False)
Here are my model classes:
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
def __str__(self):
return(self.question_text)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
rorwrong = models.BooleanField(default=False)
def __str__(self):
return(self.choice_text)