mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-04-09 01:11:04 +00:00
Basic interface done.
This commit is contained in:
parent
8dc0821539
commit
966e549ace
3 changed files with 54 additions and 9 deletions
|
|
@ -36,13 +36,20 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
<div id="model-list" class="row">
|
||||
<form id="model-list-form" class="form-inline" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="span12">
|
||||
|
||||
{% if dates %}
|
||||
<ul class="nav nav-pills">
|
||||
{% for link, date in dates %}
|
||||
<li><a href="{{ link }}">{{ date }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if view.model_admin.actions_on_top %}
|
||||
{% include 'djadmin2theme_default/includes/list_actions.html' with position='top' %}
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import division, absolute_import, unicode_literals
|
||||
|
||||
import operator
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.forms import (PasswordChangeForm,
|
||||
|
|
@ -219,15 +220,52 @@ class ModelListView(AdminModel2Mixin, generic.ListView):
|
|||
context['sort_term'] = self.request.GET.get('sort', '')
|
||||
|
||||
if self.model_admin.date_hierarchy:
|
||||
date_field = self.model_admin.date_hierarchy
|
||||
context['years'] = (
|
||||
context['object_list'].dates(date_field, "year")
|
||||
)
|
||||
context["days"] = (
|
||||
context['object_list'].dates(date_field, "day")
|
||||
)
|
||||
year = self.request.GET.get("year", False)
|
||||
month = self.request.GET.get("month", False)
|
||||
day = self.request.GET.get("day", False)
|
||||
|
||||
if year and month and day:
|
||||
context["dates"] = self._format_days(context)
|
||||
elif year and month:
|
||||
context["dates"] = self._format_days(context)
|
||||
elif year:
|
||||
context["dates"] = self._format_months(context)
|
||||
else:
|
||||
context["dates"] = self._format_years(context)
|
||||
|
||||
return context
|
||||
|
||||
def _format_years(self, context):
|
||||
return [
|
||||
(("?year=%s" % year.strftime("%Y")), year.strftime("%Y"))
|
||||
for year in
|
||||
context['object_list'].dates('published_date', 'year')
|
||||
]
|
||||
|
||||
def _format_months(self, context):
|
||||
return [
|
||||
(
|
||||
"?year=%s&month=%s" % (
|
||||
date.strftime("%Y"), date.strftime("%m")
|
||||
),
|
||||
date.strftime("%B %Y")
|
||||
) for date in
|
||||
context["object_list"].dates('published_date', 'day')
|
||||
]
|
||||
|
||||
def _format_days(self, context):
|
||||
return [
|
||||
(
|
||||
"?year=%s&month=%s&day=%s" % (
|
||||
date.strftime("%Y"),
|
||||
date.strftime("%m"),
|
||||
date.strftime("%d"),
|
||||
),
|
||||
date.strftime("%B %d")
|
||||
) for date in
|
||||
context["object_list"].dates('published_date', 'day')
|
||||
]
|
||||
|
||||
def get_success_url(self):
|
||||
view_name = 'admin2:{}_{}_index'.format(
|
||||
self.app_label, self.model_name)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Post(models.Model):
|
|||
title = models.CharField(max_length=255, verbose_name=_('title'))
|
||||
body = models.TextField(verbose_name=_('body'))
|
||||
published = models.BooleanField(default=False, verbose_name=_('published'))
|
||||
published_date = models.DateField(auto_now=True)
|
||||
published_date = models.DateField()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.title
|
||||
|
|
|
|||
Loading…
Reference in a new issue