我一直在學習django幾年,現在認爲自己是一個高級的初學者,哈哈。我正在爲一個客戶開發一個「加權問卷」(這是我可以給它的最好的名字),並且已經圍繞着去哪裏去了。django加權問卷?
客戶提出了一系列是或否的問題,根據答案,將應用某些權重。在提交結束時,我需要檢查答案並加上權重,而不是根據權重顯示建議產品的報告。權重實際上就是每個問題都有一定數量值的產品。
例如: 「你抽菸」
如果回答 「是」,然後應用 如下:核心(1),阿爾法(4), 肝(2),玉(1),還童(4)
我已經設置初始模型和管理員,但有點如何寫意見難倒。他們將能夠添加所需答案的問題,然後根據需要添加儘可能多的權重(這些是外鍵的產品)和每題的價值。
這裏是我的模型:
from django.db import models
from src.products.models import Product
"""
This app has 'yes' or 'no' questions. Each question has several 'weightings'
atached to it which are tallied at the end to recommend specific products
to the user doing the questionairre.
"""
class Question(models.Model):
"""Yes or no questions to gether enough info to recommend products via the weightings."""
ANSWER_CHOICES = (
('y', 'Yes'),
('n', 'No'),
)
GENDER_CHOICES = (
('a', 'All'),
('m', 'Male'),
('f', 'Female'),
)
question_text = models.CharField(
help_text="The text to be displayed for the question",
max_length=300
)
answer = models.CharField(
help_text="Weightings will be applied based on the answer. <br> Ex: If 'Yes' is chosen for 'Do you smoke?', then weightings will be applied if the user answers 'Yes'",
max_length=1,
choices=ANSWER_CHOICES
)
applies_to = models.CharField(
help_text="Used to filter questions based on gender of user answering the questions.",
max_length=1,
choices=GENDER_CHOICES
)
order = models.IntegerField(
help_text="Used to determine the ordering of the questions. If left blank, the question will appear after those which are ordered.",
blank=True,
null=True,
)
class Meta:
verbose_name_plural = 'questions'
ordering = ['order']
def __unicode__(self):
return self.question_text
class Weighting(models.Model):
"""References products with a specified weighting.
Added up at end to recommend products."""
question = models.ForeignKey(Question)
product = models.ForeignKey(Product)
value = models.IntegerField()
def __unicode__(self):
return '%s %s %s' % (self.question, self.product, self.value)
我手動創建的形式現在。我認爲這是最好的方法。
那麼,什麼是最好的方式來獲得答案後,然後比較答案和所需的答案,並得到所有問題的權重的總和?
總和的最後部分似乎是最困難的。
想法和建議?
編輯:使用以供參考:
http://questionnaire.corporatism.org/
感謝。我寫了類似的東西,讓我朝着正確的方向前進。 現在,我正在努力將每個問題轉化爲一種形式,通過django的表單發佈,而不是通過模板手動發佈。可能會問一個新問題。 – crobison 2010-09-02 07:48:27