Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Database Django
#1
I have a list of questions with a list of multiple choice answers.

I am trying to get details of a user who will then answer the questions and store their answers next to their name. The questions/answers may change moving forward.

I have the following code is this correct can you help please?


from django.db import models

class Investor(models.Model):
    Investor = models.CharField(max_length=100, default="")

    def __str__(self):
        return self.Investor

class Question(models.Model):
    Question_text = models.TextField(max_length=200,default="")

    def __str__(self):
        return self.Question_text

class Option(models.Model):
    Question = models.ForeignKey(Question, on_delete=models.CASCADE)
    Option = models.CharField(max_length=50, default="")

    def __str__(self):
        return self.Option

class Answer(models.Model):
    Investor = models.ForeignKey(Investor, on_delete=models.CASCADE, default="")
    Question = models.OneToOneField(
        Question,
        on_delete=models.CASCADE,
        primary_key=True,
    )
    Answer = models.OneToOneField(
        Option,
        on_delete=models.CASCADE,
        primary_key=True,
    )
Reply


Messages In This Thread
Multiple choice questions with answers linked to users - by gilesgerman - Feb-22-2018, 04:24 PM
RE: Python Database Django - by nilamo - Feb-24-2018, 06:40 PM
RE: Python Database Django - by gilesgerman - Feb-24-2018, 08:02 PM
Python Database Django - by gilesgerman - Feb-24-2018, 03:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: View is unable to find attributes of database model pythonpaul32 0 523 Dec-07-2023, 06:38 PM
Last Post: pythonpaul32
  Save JSON data to sqlite database on Django Quin 0 2,882 Mar-26-2022, 06:22 PM
Last Post: Quin
  Send email to gmail after user fill up contact form and getting django database updat Man_from_India 0 2,113 Jan-22-2020, 03:59 PM
Last Post: Man_from_India
  how retrieve database save multiple data in web Django 2.1 taomihiranga 0 2,807 Jul-30-2019, 04:58 PM
Last Post: taomihiranga
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,317 Jun-30-2019, 12:21 AM
Last Post: scidam
  Django- Remove leading zeros in values from database ntuttle 1 3,487 Mar-07-2019, 07:30 PM
Last Post: nilamo
  Django- which database i should use? with best speed and performance!! ma_norouzifar 4 4,848 Dec-10-2018, 09:47 AM
Last Post: ma_norouzifar
  How to save uploaded image url in database from Django? PrateekG 14 14,912 Jul-04-2018, 05:18 PM
Last Post: PrateekG
  Need your help to fix my database relationship in Django model PrateekG 0 2,672 Jul-02-2018, 11:08 AM
Last Post: PrateekG
  Why some Django fields are not saved in database? PrateekG 0 2,588 Jun-21-2018, 08:32 AM
Last Post: PrateekG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020