Closed jwjacobson closed 4 months ago
Yes, a simple date picker will do.
Yes, a simple date picker will do.
There's no simple way to implement a calendar widget, huh?
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
create a widgets.py in the same dir as urls/ views etc
from django.forms import DateTimeInput, DateInput
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
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.
I ended up going with the simple html5 option
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)