tasddc1226 / survey-management Goto Github PK
View Code? Open in Web Editor NEW설문지들을 관리할 수 있는 설문지 관리 웹서비스 입니다.
설문지들을 관리할 수 있는 설문지 관리 웹서비스 입니다.
## models.py
class Survey(models.Model):
"""설문지는 관리자에 의해 생성"""
author = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=100)
description = models.TextField(blank=True)
is_active = models.BooleanField(default=False)
created_at = models.DateTimeField(default=timezone.now)
class Meta:
db_table = "survey"
class Question(models.Model):
"""
하나의 설문지에 여러 질문이 존재
질문의 유형(type)은 Radio(1개), Checkbox(1개 이상), Select(1개) 중 하나
"""
RADIOBUTTON = 1
MULTIPLE = 2
SELECT = 3
TYPES_CHOICES = [
(RADIOBUTTON, "RadioButton"),
(MULTIPLE, "CheckBox"),
(SELECT, "Select"),
]
survey = models.ForeignKey(Survey, on_delete=models.CASCADE)
question_text = models.CharField(max_length=100)
answer_type = models.IntegerField(
choices=TYPES_CHOICES, default=RADIOBUTTON, max_length=32
)
class Meta:
db_table = "question"
class Choice(models.Model):
"""
하나의 질문에는 여러 보기가 존재
"""
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=100)
class Meta:
db_table = "choice"
class Submission(models.Model):
"""특정 설문지 질문들에 대한 답변 집합"""
survey = models.ForeignKey(Survey, on_delete=models.CASCADE)
created_at = models.DateTimeField(default=timezone.now)
is_complete = models.BooleanField(default=False)
class Meta:
db_table = "submission"
class Answer(models.Model):
"""특정 질문에 대한 답변"""
submission = models.ForeignKey(Submission, on_delete=models.CASCADE)
choice = models.ForeignKey(Choice, on_delete=models.CASCADE)
class Meta:
db_table = "answer"
## forms.py의 AnswerForm class
if type == 1:
choice_field = forms.ChoiceField(
choices=lists, widget=forms.RadioSelect, required=True
)
elif type == 2:
choice_field = forms.ChoiceField(
choices=lists,
widget=forms.CheckboxSelectMultiple,
required=True,
)
elif type == 3:
choice_field = forms.ChoiceField(
choices=lists, widget=forms.Select, required=True
)
mysql> select * from answer;
+----+-----------+---------------+
| id | choice_id | submission_id |
+----+-----------+---------------+
| 2 | 93 | 7 |
| 3 | 97 | 7 |
| 4 | 71 | 8 |
| 5 | 73 | 8 |
| 6 | 80 | 8 |
+----+-----------+---------------+
5 rows in set (0.00 sec)
RadioSelect
와 Select
일 때에는 한 개씩 매칭이 되므로 위와 같이 테이블에 적재 가능.CheckboxSelectMultiple
인 경우 아래와 같이 선택된 데이터가 list 형태이다.A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.