显示最新记录

时间:2014-01-20 09:40:07

标签: python mongodb jinja2 mongoengine

我有一个包含大量数据条目的MongoEngine对象,一个数据条目可能包含5个字段。

使用Jinja2如何仅显示其中一个字段,例如请考虑以下事项:

字段名称为:

  • 学校
  • studied_from
  • studied_to
  • 资格
  • fields_of_study

现在用户有2条带有上述字段的记录,我只想显示一条(最新的),我目前有这个:

Certified in {% if context.education|map(attribute="studied_to")|max %} // this gets the biggest date
    {{ context.education|map(attribute="fields_of_study")|first }} //I want to display only the field pertaining to the date displayed above.
{% endif %}
with
{% if context.job_history|map(attribute="industries")|first() == context.education|map(attribute="fields_of_study")|reverse()|first() %}
        {{ context.job_history|map(attribute="from_")-context.job_history|map(attribute="to_") }} // this is not running
        {% endif %}
experience
{{ context.education|map(attribute="studied_to")|max|datetime }}
...

问题是最“最近的”fields_of_study不会永远是第一个。

如何只显示如上所示的most recent记录?

0 个答案:

没有答案
相关问题