2

I am trying to create a simple test program for a site. Basically the user will enter in a large amount of JSON. Then I will parse the JSON and get 10 random properties from the JSON. Then I will display those 10 properties and ask the user what the answer is. Then I am going to store the users answer in the admin panel as a way for me to check if they were right or wrong.

Basically I want to keep track of

property      user_answer      correct_answer

But I would like to keep it as a single item.

1 Answer 1

3

If you are using PostgreSQL you can store multiple strings in an ArrayField and thus keep them as a single item like this:

from django.contrib.postgres.fields import ArrayField
from django.db import models


class YourModel(models.Model):
    answers = ArrayField(models.CharField(max_length=255))
    # other fields for your model

If however, you are not using PostgreSQL as your database, you have to store the data in different fields like this:

from django.db import models


class YourModel(models.Model):
    user_answer = models.CharField()
    correct_answer = models.CharField()
    # other fields for your model
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.