Thursday, April 28, 2016

Complex content type

Need to build a content type that accepts inputs from users. Those inputs must be stored in database alone with information who entered it (user's information like user name). 

Here is what I am looking to build:



 Here is how my models.py looks at the moment. 

from django.contrib.auth.models import User
from django.db import models


# Create your models here.
class Unit(models.Model):
    unit_number = models.PositiveIntegerField(blank=True, null=True, default=1)
    title = models.CharField(max_length=150, blank=True, null=True)
    scripture_ref = models.CharField(max_length=250, blank=True, null=True)

    def __str__(self):
        return self.title


class Subsection(models.Model):
    title = models.CharField(max_length=150, blank=True, null=True)
    subsection_text = models.TextField(default='SUBSECTION TEXT')
    unit = models.ForeignKey(Unit, on_delete=models.CASCADE)


class Question(models.Model):
    question_text = models.CharField(max_length=2000, default='QUESTION TEXT')
    subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)
    
    
class Answer(models.Model):
    answer = models.TextField(blank=True, null=True) # this field I want to store alone with question_text and answered_by fields
    answered_by = models.ForeignKey(User, blank=True, null=True, related_name='answers')

I am probably asking a lot, but I hope that there will be someone who can help. My question is what should I do with models.py, forms.py and views.py to put together this kind of content type?

Thank you in advance!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/69ca76f4-a839-4113-902a-89e4b0cb0d6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment