django-grappelli-filters icon indicating copy to clipboard operation
django-grappelli-filters copied to clipboard

Add datetime range filter

Open frnhr opened this issue 10 years ago • 9 comments

frnhr avatar Mar 29 '14 03:03 frnhr

Is there any simple way to implement this for admin list?

w495 avatar Sep 08 '14 15:09 w495

Two things to implement here:

  1. filter URL params
  2. 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 :)

frnhr avatar Sep 08 '14 16:09 frnhr

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.

w495 avatar Sep 12 '14 14:09 w495

hi, you changed this in change_list_filter_sidebar.html ?

neokeats avatar Oct 08 '14 08:10 neokeats

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.

w495 avatar Nov 13 '14 22:11 w495

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 avatar May 15 '15 10:05 mtford90

@mtford90 :+1:

pricco avatar Sep 11 '15 18:09 pricco

Very nice, but I suggest to change <label>Date</label> to <label>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</label>

it-management avatar May 20 '16 15:05 it-management

Two things to implement here:

  1. filter URL params
  2. 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

venqics avatar Mar 01 '22 07:03 venqics