mirror of
https://github.com/jazzband/django-constance.git
synced 2026-03-16 22:40:24 +00:00
Merge pull request #243 from whs/master
Fix Reset to default for DateTime, #185
This commit is contained in:
commit
3f6b694f74
3 changed files with 19 additions and 3 deletions
|
|
@ -195,6 +195,7 @@ class ConstanceAdmin(admin.ModelAdmin):
|
|||
'form_field': form[name],
|
||||
'is_checkbox': isinstance(
|
||||
form[name].field.widget, forms.CheckboxInput),
|
||||
'is_datetime': isinstance(default, datetime),
|
||||
}
|
||||
|
||||
return config_value
|
||||
|
|
|
|||
|
|
@ -2,13 +2,19 @@
|
|||
'use strict';
|
||||
|
||||
$(function() {
|
||||
|
||||
$('#content-main').on('click', '.reset-link', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var field = $('#' + this.dataset.fieldId);
|
||||
var fieldType = this.dataset.fieldType;
|
||||
|
||||
if (field.attr('type') === 'checkbox') {
|
||||
if (fieldType === 'checkbox') {
|
||||
field.prop('checked', this.dataset.default === 'true');
|
||||
} else if (fieldType === 'datetime') {
|
||||
var defaultDate = new Date(this.dataset.default * 1000);
|
||||
$('#' + this.dataset.fieldId + '_0').val(defaultDate.strftime(get_format('DATE_INPUT_FORMATS')[0]));
|
||||
$('#' + this.dataset.fieldId + '_1').val(defaultDate.strftime(get_format('TIME_INPUT_FORMATS')[0]));
|
||||
} else {
|
||||
field.val(this.dataset.default);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,18 @@
|
|||
{{ item.form_field.errors }}
|
||||
{{ item.form_field }}
|
||||
<br>
|
||||
<a href="#" class="reset-link" data-field-id="{{ item.form_field.auto_id }}" data-default="{% spaceless %}
|
||||
<a href="#" class="reset-link"
|
||||
data-field-id="{{ item.form_field.auto_id }}"
|
||||
data-field-type="{% spaceless %}
|
||||
{% if item.is_checkbox %}checkbox
|
||||
{% elif item.is_datetime %}datetime
|
||||
{% endif %}
|
||||
{% endspaceless %}"
|
||||
data-default="{% spaceless %}
|
||||
{% if item.is_checkbox %}{% if item.raw_default %} true {% else %} false {% endif %}
|
||||
{% else %}{{ item.default }}{% endif %}
|
||||
{% elif item.is_datetime %}{{ item.raw_default|date:"U" }}
|
||||
{% else %}{{ item.default }}
|
||||
{% endif %}
|
||||
{% endspaceless %}">Reset to default</a>
|
||||
</td>
|
||||
<td>
|
||||
|
|
|
|||
Loading…
Reference in a new issue