Poll
假设我在我的对象中有这个类models.py
:
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
# Opened by default.
is_opened = True
def close_poll(self):
self.is_opened = False
# Don't know how to implement this...
def open_poll(self):
self.is_opened = True
# Don't know how to implement this...
def pub_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date < now
pub_recently.admin_order_field = 'pub_date'
pub_recently.boolean = True
pub_recently.short_description = 'Published recently?'
当我在其中使用该close_poll
函数时,python manage.py shell
它会将is_opened
变量设置为False
. 但它保持设置为False
仅用于这一个 shell 会话。
那么我怎样才能巧妙地实现呢?