2
我必须表明在Django应用程序按日期条目和我有点堵塞: 这里是我的模型的例子:Django的注释上的“自定义字段” Django的排序
class Event(models.Model):
name = models.CharField(max_length=100)
theme = models.ForeignKey(Theme)
...
class Date(models.Model):
event = models.ForeignKey(Event)
start = models.DateField()
end = models.DateField()
class Meta:
ordering = ['start', 'end']
unique_together = ['event', 'start']
我得到了拿在数据库中的所有事件的看法:)Event.objects.all(
,然后在模板中我展示他们的主题和其他东西,例如日期开始的事件列表。 我想在列表中显示的第一个“未来”的日期,这很容易对事件模型的自定义方法:
def get_first_future_date(self):
today = datetime.datetime.now()
dates = self.date_set.filter(end__gte=today)
if dates:
return dates[0]
这种方法的第一个将来的日期,或者没有完成的最早日期。
Here's the problem : I would like to show that field in my template and be able to sort it with django-sorting.
Django的排序使用{%锚ARG%}做,但我不知道如何来管理它那场... 你会怎么做???
感谢由事先的任何答复。
我坚持在同样的情况。你有没有找到解决方案? – Konstant 2011-05-05 15:41:23