django-grappelli-filters
django-grappelli-filters copied to clipboard
Add datetime range filter
Is there any simple way to implement this for admin list?
Two things to implement here:
- filter URL params
- two datepickers in the GUI
The first part should work automagically, just by using __gte=yyyy-mm-dd and __lte=yyyy-mm-dd format.
As for the GUI, I know that grappelli's datepicker can be reused, because I've done it once before. But that was a few years back, so I hope the same trick will still work.
I'm planning to implement this within a week or so, so if you feel like waiting for it, be my guest. Pull requests also welcome :)
I use django_datefilter
(https://github.com/tzulberti/django-datefilterspec)
The main problem is in grappelli.initDateAndTimePicker();
I've resolved this within
<script type="text/javascript" charset="utf-8">
(function($) {
$(document).ready(function() {
grappelli.initDateAndTimePicker();
setTimeout(grappelli.initDateAndTimePicker, 100);
});
})(grp.jQuery);
</script>
May be. this is duct tape, but works. But I have problems with neighbor filters.
hi, you changed this in change_list_filter_sidebar.html ?
No. I use https://github.com/DXist/django-daterange-filter/blob/master/daterange_filter/templates/daterange_filter/filter.html
I've changed this in daterange_filter/filter.html
. Now my file looks like this https://gist.github.com/w495/6284d21ba7406c658075
Also, I think movement javascripts' block to the end of base-file can help in several cases.
To make django-daterange-filter look reasonable for me (grappelli on django 1.8) I expanded upon @w495's changes to filter.html to look like the following:
{% load i18n %}
{% load i18n admin_urls admin_static admin_list %}
{{ spec.form.media }}
{% block extrahead %}
<style>
.ui-datepicker-div {
top: 246px;
}
.daterange_form p {
margin-left: auto;
margin-right: auto;
margin-bottom: 5px;
}
.daterange_form input.grp-button-time {
width: 20%;
height: auto;
}
.grp-button-time {
float: right;
width: 55px !important;
}
</style>
{% endblock %}
{% block javascripts %}
<script type="text/javascript" charset="utf-8">
(function ($) {
$(document).ready(function () {
grappelli.initDateAndTimePicker();
setTimeout(grappelli.initDateAndTimePicker, 1000);
});
})(grp.jQuery);
</script>
{% endblock %}
<form class='daterange_form grp-module'
method="GET"
action=""
accept-charset="utf-8"
enctype="text/plain">
<div class='grp-row'>
<label>Date</label>
{{ spec.form.as_p }}
<input type="submit" class="grp-button-time" value="{% trans "Filter" %}">
</div>
</form>
@mtford90 :+1:
Very nice, but I suggest to change
<label>Date</label>
to
<label>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</label>
Two things to implement here:
- filter URL params
- two datepickers in the GUI
The first part should work automagically, just by using __gte=yyyy-mm-dd and __lte=yyyy-mm-dd format.
As for the GUI, I know that grappelli's datepicker can be reused, because I've done it once before. But that was a few years back, so I hope the same trick will still work.
I'm planning to implement this within a week or so, so if you feel like waiting for it, be my guest. Pull requests also welcome :)
where is the code for the same