class Survey models Model user models ForeignKey get_user_model verbos

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Survey(models.Model):
user = models.ForeignKey(get_user_model(), verbose_name=u'пользователь',
related_name=u'gallup', unique=True)
stageur = models.IntegerField(verbose_name=u'стаж работы')
period = models.ForeignKey(Period, verbose_name=u'период')
class Meta:
verbose_name = u'опрос'
verbose_name_plural = u'опрос'
db_table = 'action_hierarchy_opros'
def __unicode__(self):
return unicode(self.user)
def avg(self):
arr = [ans.value for ans in self.answers.all()]
return numpy.nanmean(arr)
def avg_stageur(self):
arr = [ans.value for ans in self.answers.all()[:10]]
return numpy.nanmean(arr)
def is_ready(self):
return self.answers.count() > 0
is_ready.short_description = u'готов'
is_ready.boolean = True
class Answer(models.Model):
opros = models.ForeignKey("gallup.Survey", verbose_name=u'опрос',
related_name="answers")
question = models.ForeignKey(Question, verbose_name=u'вопрос')
VALUE_CHOICES = (
(5, u'5 - абсолютно согласен(a)'),
(4, u'4 - согласен(а)'),
(3, u'3 - скорее согласен(а)'),
(2, u'2 - скорее несогласен(а)'),
(1, u'1 - абсолютно несогласен(а)'),
)
value = models.PositiveSmallIntegerField(u'значение', choices=VALUE_CHOICES)
comment = models.TextField(u'комментарий', blank=True, null=True)
class Meta:
verbose_name = u'ответ опроса'
verbose_name_plural = u'ответы опросов'