为什么我的数据没有更新?

时间:2017-06-12 12:05:47

标签: django python-2.7 django-models django-1.8

这是数据库的模型,用户更改重要性,并根据用户选择的级别,分配分数/点 但是无论选择什么,所有它都显示为my_points为300,its_points为0。

my_xpath = "//div[@id='job_14']/a"
my_text = tree.xpath(my_xpath)
my_text = my_text.text

1 个答案:

答案 0 :(得分:1)

您的代码不必要地复杂化。你真的不需要分开的my_pointsmy_answer_importance字段以及你使用选择的方式,有点打击使用选择的全部要点。我建议你改变你的代码:

LEVELS = (
    (300, 'Mandatory'),
    (200, 'Very Important'),
    (50, 'Somewhat Important'),
    (0, 'Not Important'),
    )

class UserAnswer(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    question = models.ForeignKey(Question)
    my_answer = models.ForeignKey(Answer, related_name = 'user_answer')
    my_points = models.IntegerField(default=-1, choices=LEVELS)
    their_answer = models.ForeignKey(Answer, null=True, blank=True, related_name = 'match_answer')
    their_points = models.IntegerField(default=-1, choices=LEVELS)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)

    def __unicode__(self):
        return self.my_answer.text[:10]

现在您不需要您的信号,并且可以移除整个代码块。