我有两个相似的模型,但在渲染时它的行为有所不同。我的前两个模型是:
class Sitting(models.Model):
sit_date = models.DateField(blank=False,unique=True)
cut_off_date = models.DateField(null=True, blank=True)
ballot_date = models.DateField(null=True, blank=True)
class Circular(models.Model):
cir_no = models.IntegerField(blank=False)
sit_start_date = models.DateField(blank=False)
sit_end_date = models.DateField(blank=False)
@property
def ballot(self):
qs = Sitting.objects.filter(sit_date=self.sit_start_date)
return qs
并在模板中:
{% for b in c.ballot %}
<p>ballot: {{ b.ballot_date }}</p>
{% endfor %}
它给出了正确的日期。但是,当我使用以下两个与上面几乎相同的模型时,它什么都没有显示:
class NewSitting(models.Model):
sit_date = models.DateField(blank=False, unique=True)
new_sit_date = models.DateField(null=True, blank=True, unique=True)
cut_off_date = models.DateField(null=True, blank=True)
ballot_date = models.DateField(null=True, blank=True)
def get_new_sit_date(self):
return self.sit_date
def save(self, *args, **kwargs):
if not self.new_sit_date:
self.new_sit_date = self.get_new_sit_date()
super(NewSitting, self).save(*args, **kwargs)
class Circular(models.Model):
cir_no = models.IntegerField(blank=False)
sit_start_date = models.DateField(blank=False)
sit_end_date = models.DateField(blank=False)
def newballot(self):
qs = NewSitting.objects.filter(new_sit_date=self.sit_start_date)
return qs
并在模板中:
{% for b in c.newballot %}
<p>ballot: {{ b.ballot_date }}</p>
{% endfor %}
此模板不显示任何内容。我在哪里做错了?