Używam wyboru miesiąca w formacie jQuery (bez daty) o formacie: 201110.Wybór miesiąca jquery: ustawianie początkowego zakresu min/maks powoduje konflikt z funkcją "od" <"do"
Chcę ustawić datę min (patrz w kodzie), więc najpierw zdefiniuj ją w django forms.py data-min, a następnie przeanalizuj tę datę w html. Najpierw jest zakres min/maks. (choć to nie działa teraz).
Następnie, aby data "do" była zawsze późniejsza niż data "od", potrzebuję również funkcji min/max, a następnie zastępuje poprzednie zakresy miesięcy ustawiane z SQL.
Sytuacja w walutach to, że mogę zrealizować "na" datę> "od" daty. Ale data min (pochodząca z MYSQL) nie działa teraz.
Jak mogę rozwiązać ten konflikt, proszę, powiedz mi. Z góry dziękuję
Dziękujemy za odpowiedź z góry.
<script type="text/javascript">
$(function() {
$("#from, #to").datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'yy MM',
minDate: $(this).date-min, ///it is here doesn't work, the minDate is coming from Django
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
},
beforeShow : function(input, inst) {
if ((datestr = $(this).val()).length > 0) {
year = datestr.substring(datestr.length-4, datestr.length);
month = jQuery.inArray(datestr.substring(0, datestr.length-5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
$(this).datepicker('setDate', new Date(year, month, 1));
}
var other = this.id == "from" ? "#to" : "#from";
var option = this.id == "from" ? "maxDate" : "minDate";
if ((selectedDate = $(other).val()).length > 0) {
year = selectedDate.substring(selectedDate.length-4, selectedDate.length);
month = jQuery.inArray(selectedDate.substring(0, selectedDate.length-5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker("option", option, new Date(year, month, 1));
}
}
});
$("#btnShow").click(function(){
if ($("#from").val().length == 0 || $("#to").val().length == 0){
alert('All fields are required');
}
else{
alert('Selected Month Range :'+ $("#from").val() + ' to ' + $("#to").val());
}
})
});
</script>
Jak mogę określić moje min aktualne Django:
W models.py
class XXX(models.Model):
start_date=models.DateField(auto_now_add=True)
end_date=models.DateField(auto_now_add=True)
W forms.py
class Meta:
model = XXX
fields = ('start_date','end_date')
date_min=XXX.objects.all().aggregate(Min('date')) <this field is NOT defined in models.py, is that OK?; and format is like 2011-11-01 -->
widgets = {
'start_date': forms.DateInput(attrs={'class':'datepicker',
'date-min':date_min,
}),
}
Nie można kruszywo na polu nieokreślonym. Jak chcesz zdefiniować 'date_min'? – Uri