jwjacobson / jazztunes

a jazz repertoire management app
https://jazztunes.org
GNU General Public License v3.0
3 stars 0 forks source link

Add set last_played option when creating a tune or taking a public tune #224

Closed jwjacobson closed 4 months ago

jwjacobson commented 4 months ago

Use of the app over the past few weeks has demonstrated to me that the last_played field is crucial to the app's functioning, so users should be able to set this whenever a tune comes into their repertoire, either via creation or taking. I think a calendar widget will do the job alright (and of course they can still leave it blank)

ryaustin commented 4 months ago

Yes, a simple date picker will do.

jwjacobson commented 4 months ago

Yes, a simple date picker will do.

There's no simple way to implement a calendar widget, huh?

ryaustin commented 4 months ago

Well the datepicker in html5 is a full calendar widget so it's a win.

You can also have your pick of the liter with various templates. Use this tutorial: https://simpleisbetterthancomplex.com/tutorial/2019/01/03/how-to-use-date-picker-with-django.html

In a nutshell

  1. create a widgets.py in the same dir as urls/ views etc

  2. from django.forms import DateTimeInput, DateInput

  3. add the following: (note that the widgets folder should be placed in tune/templates/tune)

    template_name = 'tune/widgets/bootstrap_datetimepicker.html'
    
    def get_context(self, name, value, attrs):
        datetimepicker_id = 'datetimepicker_{name}'.format(name=name)
        if attrs is None:
            attrs = dict()
        attrs['data-target'] = '#{id}'.format(id=datetimepicker_id)
        attrs['class'] = 'form-control datetimepicker-input'
        context = super().get_context(name, value, attrs)
        context['widget']['datetimepicker_id'] = datetimepicker_id
        return context
  4. finally add bootstrap_datetimepicker.html in the widgets folder:

<div class="input-group date" id="{{ widget.datetimepicker_id }}" data-target-input="nearest">
    {% include "django/forms/widgets/input.html" %}
    <div class="input-group-append" data-target="#{{ widget.datetimepicker_id }}" data-toggle="datetimepicker">
      <div class="input-group-text"><i class="fa fa-calendar"></i></div>
    </div>
  </div>

  <script>
    $(function () {
      $("#{{ widget.datetimepicker_id }}").datetimepicker({
        format: 'DD/MM/YYYY HH:mm',
      });
    });
  </script>

This should work, but follow the template if you get stuck, or let me know.

jwjacobson commented 4 months ago

I ended up going with the simple html5 option