【发布时间】:2017-05-01 13:49:42
【问题描述】:
我想缓存以下模型和每个问题的缩短链接。
class Question(models.Model):
question_text = models.CharField('text', max_length=200)
pub_date = models.DateTimeField('publication date', default=timezone.now)
allow_multiple_choices = models.BooleanField(default=False)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField('text', max_length=200)
votes = models.IntegerField('votes', default=0)
def __str__(self):
return self.choice_text
我应该如何生成密钥?这样就够了吗?
cache.set('question' + question.id, question)
cache.set('shortened' + question.id, shortened)
【问题讨论】: