I have n number of dates defined in this below model in the database, these are directly inserted by admin, not by modelforms or anything.
class Calendar(models.Model):
date = models.DateField()
occasion = models.CharField(max_length = 20)
the form that has the date fields,
class LeaveRequestForm(ModelForm):
class Meta:
fields = (... "from_date", "to_date" ...)
model = Leave
widgets = {
...
'from_date' : DateInput(attrs={'class': 'datepicker'}),
'to_date' : DateInput(attrs={'class': 'datepicker'}),
...
}
I have this datepicker script which disable weekends,
<script>
$(document).ready(function() {
$('.datepicker').datepicker(
{
minDate : 0,
beforeShowDay : $.datepicker.noWeekends
}
);
});
</script>
Now I want to disable the dates defined in the database + weekends as well. How do I do that?
update :
var array = {{
{% for x in disabled_dates %}
{{x.dates}}
{% endfor %}
}}
$('datepicker').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
return array.indexOf(string) != -1 ? [false] : $.datepicker.noWeekends(date);
}
});
No luck yet!