如何在 Django 中进行可定制的用户调查
我正在为一家公司制作一个系统,其中必须保存有关各种事物的满意度的信息,我已经使用带有固定问题和答案的固定模型使其正常工作,但我确信他们需要更改或添加问题。
因此,我想创建一个系统,用户可以在其中创建由他们定义的自定义问题组成的自定义评估模式。 我该如何进行这样的设计?
现在我的模型是这样的,但是错误的:
RATING_CHOICES = ((0, u"Good"), (1, u"Bad"), (2, u"Dunno"),)
class EvaluationScheme(models.Model):
title = models.CharField(max_length=200)
class Evaluation(models.Model):
doctor = models.CharField(max_length=200)
agency = models.CharField(max_length=200)
scheme = models.ForeignKey(EvaluationScheme)
class EvaluationQuestion(models.Model):
question = models.CharField(max_length=200)
evaluation = models.ForeignKey(EvaluationScheme)
def __unicode__(self):
return self.question
class EvaluationAnswer(models.Model):
evaluation = models.ForeignKey(Evaluation)
question = models.ForeignKey(EvaluationQuestion)
answer = models.SmallIntegerField(choices=RATING_CHOICES)
这就是我想要的,除了评估方案是无用的,因为你仍然必须自己选择所有问题和答案 - 它不显示仅与相关的问题的列表选择的模式。
I am making a system for a company which among other things must hold information about the satisfactory level about various things, I have made it work fine using a fixed model with fixed questions and answers, but I am sure that they will need to change or add questions.
So I want to make a system where users can make custom evaluation schemas that consists of custom questions defined by them. How do I go about making such a design?
Right now my model is this, but wrong:
RATING_CHOICES = ((0, u"Good"), (1, u"Bad"), (2, u"Dunno"),)
class EvaluationScheme(models.Model):
title = models.CharField(max_length=200)
class Evaluation(models.Model):
doctor = models.CharField(max_length=200)
agency = models.CharField(max_length=200)
scheme = models.ForeignKey(EvaluationScheme)
class EvaluationQuestion(models.Model):
question = models.CharField(max_length=200)
evaluation = models.ForeignKey(EvaluationScheme)
def __unicode__(self):
return self.question
class EvaluationAnswer(models.Model):
evaluation = models.ForeignKey(Evaluation)
question = models.ForeignKey(EvaluationQuestion)
answer = models.SmallIntegerField(choices=RATING_CHOICES)
This is sort of what I want, except that the EvaluationScheme is useless, since you still have to chose all questions and answers yourself - it does not display a list of only the questions related to the schema of choice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为你的模型很好。 我使用 Django 管理员创建了一个包含评估问题的评估方案,然后我创建了一个评估并且能够回答它的问题。 这是我用来处理你的模型的代码:
I think your models are fine. I used the Django admin to create an EvaluationScheme with EvaluationQuestions, then I created an Evaluation and I was able to answer its questions. Here's the code I used to go with your models:
您检查过 django-survey 吗? 非常整洁。
Have you checked django-survey? It's pretty neat.
Django-crowdaround 是 django-survey 的一个分支,自 2012 年起一直在积极维护,目标是姜戈 1.2+。
Django-crowdsourcing is a fork of django-survey that is actively maintained as of 2012 and targets Django 1.2+.
不是 django 专家,因此您可能希望等待更有经验的人来回答,但您可以尝试以下操作:
也可以将关系反过来,取决于您需要如何访问数据。
Not a django expert so you might wish to wait for a more experience person to answer but you could try something like:
Could also put the relationships the other way around, depends how you need to access the data.