我只是好奇的方式Django自動生成方法靈活的參數名稱,如c = p.choice_set.filter(choice_startswith = 'Just hacking')
你能解釋基本上它怎麼可以做?django如何自動生成方法?
這是例子
import datetime
from django.db import models
from django.utils import timezone
class Poll(models.Model):
question = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days = 1)
def __unicode__(self):
return self.question
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length = 200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
對不起。我不確定你是什麼意思。你能詳細闡述一下嗎? – 2012-08-13 20:22:10