Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add form and question models #25

Merged
merged 3 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions osp/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from django.contrib import admin

from osp.models import *
from osp.models import (
UserInformation, Form, Question, Choice,
Checkbox, Dropdown, Paragraph, ShortAnswer,
Date, Time, FileUpload
)

admin.site.register(UserInformation)
# admin.site.register(Form)
# admin.site.register(Question)
models = [
UserInformation, Form, Question, Choice,
Checkbox, Dropdown, Paragraph, ShortAnswer,
Date, Time, FileUpload
]

admin.site.register(models)
45 changes: 45 additions & 0 deletions osp/migrations/0003_form_question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 3.0.7 on 2020-06-20 14:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('osp', '0002_auto_20200609_1626'),
]

operations = [
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(auto_now_add=True)),
('updated_on', models.DateTimeField(auto_now=True)),
('label', models.CharField(max_length=255)),
('data_type', models.CharField(choices=[('char', 'Short Answer'), ('text', 'Paragraph Answer'), ('choice', 'Choice'), ('checkbox', 'Checkbox'), ('dropdown', 'Dropdown'), ('file', 'File Upload'), ('date', 'Date'), ('time', 'Time')], max_length=8)),
('description', models.TextField(blank=True)),
('order', models.PositiveIntegerField()),
('required', models.BooleanField(default=False)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Form',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField(blank=True)),
('created_on', models.DateTimeField(auto_now_add=True)),
('updated_on', models.DateTimeField(auto_now=True)),
('published_status', models.BooleanField(default=False)),
('target_user', models.CharField(choices=[('all', 'All Users'), ('admin', 'Admin'), ('student', 'Student')], default='all', max_length=7)),
('form_fields', models.ManyToManyField(blank=True, default=None, to='osp.Question')),
],
options={
'abstract': False,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Generated by Django 3.0.7 on 2020-06-20 15:27

import django.contrib.postgres.fields
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('osp', '0003_form_question'),
]

operations = [
migrations.CreateModel(
name='Checkbox',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
('options', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=255), size=None)),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='Choice',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
('options', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=255), size=None)),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='Date',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='Dropdown',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
('options', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(blank=True, max_length=255), size=None)),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='FileUpload',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='Paragraph',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='ShortAnswer',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
migrations.CreateModel(
name='Time',
fields=[
('question_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='osp.Question')),
],
options={
'abstract': False,
},
bases=('osp.question',),
),
]
18 changes: 18 additions & 0 deletions osp/migrations/0005_auto_20200625_1656.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-06-25 16:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('osp', '0004_checkbox_choice_date_dropdown_fileupload_paragraph_shortanswer_time'),
]

operations = [
migrations.AlterField(
model_name='question',
name='data_type',
field=models.CharField(choices=[('char', 'Short Answer'), ('text', 'Paragraph Answer'), ('choice', 'Choice'), ('checkbox', 'Checkbox'), ('dropdown', 'Dropdown'), ('file', 'File Upload'), ('date', 'Date'), ('time', 'Time')], default='char', max_length=8),
),
]
9 changes: 7 additions & 2 deletions osp/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from osp.models.user_information import UserInformation
# from osp.models.form import Form
# from osp.models.question import Question
from osp.models.form import Form
from osp.models.question import Question
from osp.models.abstract_timestamp import AbstractTimestamp
from osp.models.field import (
Choice, Dropdown, Checkbox, Paragraph,
ShortAnswer, Date, Time, FileUpload
)
13 changes: 13 additions & 0 deletions osp/models/abstract_timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.db import models

class AbstractTimestamp(models.Model):
"""
Abstract model for Created Time and Updated Time fields
"""

created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)

class Meta:

abstract = True
62 changes: 62 additions & 0 deletions osp/models/field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from django.db import models
from django.contrib.postgres.fields import ArrayField

from osp.models.question import Question

class Choice(Question):
bismitaguha marked this conversation as resolved.
Show resolved Hide resolved

options = ArrayField(
models.CharField(
max_length=255,
blank=True
))

def __str__(self):
return f'{self.label}'

class Dropdown(Question):

options = ArrayField(
models.CharField(
max_length=255,
blank=True
))

def __str__(self):
return '{self.label}'

class Checkbox(Question):

options = ArrayField(
models.CharField(
max_length=255,
blank=True
))

def __str__(self):
return '{self.label}'

class Paragraph(Question):

def __str__(self):
return '{self.label}'

class ShortAnswer(Question):

def __str__(self):
return '{self.label}'

class Date(Question):

def __str__(self):
return '{self.label}'

class Time(Question):

def __str__(self):
return '{self.label}'

class FileUpload(Question):

def __str__(self):
return '{self.label}'
24 changes: 24 additions & 0 deletions osp/models/form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models

from osp.models.question import Question
from osp.models.abstract_timestamp import AbstractTimestamp
from osp.utils import target_user_types

class Form(AbstractTimestamp):

name = models.CharField(max_length=255)
description = models.TextField(blank=True)
published_status = models.BooleanField(default=False)
form_fields = models.ManyToManyField(
to=Question,
default=None,
blank=True,
)
target_user = models.CharField(
max_length=7,
choices=target_user_types.TARGET_USERS,
default='all'
)

def __str__(self):
return f'{self.name}'
16 changes: 16 additions & 0 deletions osp/models/question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.db import models

from osp.models.abstract_timestamp import AbstractTimestamp
from osp.utils import question_types

class Question(AbstractTimestamp):

label = models.CharField(max_length=255)
data_type = models.CharField(
bismitaguha marked this conversation as resolved.
Show resolved Hide resolved
max_length=8,
Monal5031 marked this conversation as resolved.
Show resolved Hide resolved
choices=question_types.DATA_TYPES,
default='char'
)
description = models.TextField(blank=True)
order = models.PositiveIntegerField()
required = models.BooleanField(default=False)
12 changes: 3 additions & 9 deletions osp/models/user_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
from django.contrib.auth.models import User
from django.db import models

ADM = 'admin'
STU = 'student'
USER = (
(ADM, 'Admin'),
(STU, 'Student'),
)
from osp.utils import user_types

class UserInformation(models.Model):

Expand All @@ -18,10 +13,9 @@ class UserInformation(models.Model):
name = models.CharField(max_length=255)
user_type = models.CharField(
max_length=7,
choices=USER,
choices=user_types.USERS,
default='student'
)

def __str__(self):

return f'{self.name}: {self.user_type}'
return f'{self.name}: {self.user_type}'
18 changes: 18 additions & 0 deletions osp/utils/question_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
SA = 'char'
PA = 'text'
CF = 'choice'
CH = 'checkbox'
DD = 'dropdown'
FI = 'file'
DA = 'date'
TI = 'time'
DATA_TYPES = (
(SA, 'Short Answer'),
(PA, 'Paragraph Answer'),
(CF, 'Choice'),
(CH, 'Checkbox'),
(DD, 'Dropdown'),
(FI, 'File Upload'),
(DA, 'Date'),
(TI, 'Time')
)
8 changes: 8 additions & 0 deletions osp/utils/target_user_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALL = 'all'
ADM = 'admin'
STU = 'student'
TARGET_USERS = (
(ALL, 'All Users'),
(ADM, 'Admin'),
(STU, 'Student'),
)
6 changes: 6 additions & 0 deletions osp/utils/user_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ADM = 'admin'
STU = 'student'
USERS = (
(ADM, 'Admin'),
(STU, 'Student'),
)