python - Sorting and grouping objects by Date with the Django ORM -


I have a paragraph model in which there is a date field, I want to ask questions against all paragraph objects, and for each specific year Along with a datatype, and then each separate month.

For example

Archives = {2009: {12, [,, ...], 11: [...]}, 2008: {12, [...], 11: [...]},}

Is it possible?

This type of question takes a long time, the simplest solution is through the data and group of year and month You can see it in your hand or use it in your template. It really depends on what you want to do with the data.

If you have a year and month grouping archives to apply, it is a very common thing, you may want to consider creating a one year and month field, which you populate when saved. .

This may be something by hand:

  arch = {} for archiving. Objects.all (): year = arch.get (a.pub_date.year, {}) months = year.get (a.pub_date.month, []) month .append (a) year [a.pub_date.month] = Arch of Arc [a.pub_date.year] = year  

or grouped logic (without trial) using the template:

  {% Reorganization archive by% pub_date.year as year_list%} year% year_list%}. Year: {{Year.grouper}} {% month_list%} month {% month_list%} month by pub_date.month regroup year.list month: {{month.grouper}} {% month.list%} {{Collection}} {% endfor%} {{endfor%} {{endfor%} {{endfor%}} {/ 

for collection in I try to present logic instead of logic instead of logic Li>


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -