I am creating a flashcard and quizzes website powered by AI. I have most features developed and I am stuck on one problem.
How do I structure a database for flashcards? Each flashcard set needs to have a “Title” and multiple “Questions” and “Answers” in each Flashcard set. Users should be able to create multiple Flashcard sets.
How should I go about structuring the database and how would I display each Flashcard set and its Question and Answers within it?
I guess the only thing to discuss here is about how to define the DB schema for Questions and Answers. It seems clear that Flashcard should be a datatype on its own.
- Is the number of questions and answers in a Flashcard fixed by design? No chance to change this number in the future?
- Will flashcard be searched by questions or answers inside?
- Are answers bound to questions in a 1:1 relationship?
Without further information, and leaving a reasonably scalable structure, I’d define it as follows.
Flashcard
- Title (text)
- Q&A (List of Q&A)
- Owner (User)
Q&A
- Question (text)
- Answer (text)
- Owner (User)
Thank you, this helped. Now that I have set this up I am having troubles setting a custom state to actually save the selected “Q&A” to “Flashcards”.
Basically, users input their class notes and I have the Open AI API set up to return JSON Objects in repeating groups displaying Question and Answer, and a “Save” button. Users should be able to select all the “Q&A” they want to add to their Flashcard set and then give it a title and save that list to 'Flashcards" under the title the user gave it.
My problem is setting a custom state with a json object, here is a screenshot of where I got stuck.
I think you’ll want to process that JSON a bit before adding it directly to a custom state to be shown to the user right?
Here is a Loom video of me explaining my issue. Please let me know if you need more info I can create another video.
Thanks!
OK, I misunderstood what you wanted in my first answers.
There are 2 datatypes here:
Flashcard
- Question (text)
- Answer (text)
FlashcardSet
- Flashcards (List of Flashcards)
- Title (text)
- Owner (User)
When clicking Save (I’d rather name it Add) on a certain Flashcard you can save it somewhere, e.g. a page’s custom state. Later on, when the user has selected all the flashcards he wants for the flashcard set, he can save it by pressing a button (yours is named Go to My Flashcard Set, which does not communicate well what it does, I’d simply name it Save Flashcard Set). The saving process implies creation of a new FlashcardSet record, creation of all selected Flashcard objets, and adding all those to the former.