我只是好奇 Django 自动生成具有灵活参数名称的方法的方式,比如c = p.choice_set.filter(choice_startswith = 'Just hacking')
你能解释一下它是如何完成的吗?
这是示例的代码
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