After customizing the date format in the Django modelform widget and jQuery datepicker, I encountered an error indicating that the field is not valid.
class Sale_Invoice_Main_Page(forms.ModelForm):
class Meta:
model = SaleInvoice
fields = '__all__'
exclude = ['created_at','updated_at','transiction_type']
widgets = {'description' : forms.TextInput(attrs={ 'placeholder' : 'description'}),
'invoice_no' : forms.TextInput(attrs={ 'readonly' : 'True'}),
'total_amount' : forms.TextInput(attrs={ 'readonly' : 'True'}),
'invoice_date' : forms.DateInput(attrs={ 'class' : "vdate" },format=('%d-%m-%Y')),
'due_date' : forms.DateInput(attrs={ 'readonly' : "True" },format=('%d-%m-%Y')),
}
class SaleInvoice(models.Model):
customer = models.ForeignKey(Customer_data , on_delete=models.CASCADE)
invoice_date = models.DateField(null=True,blank=True)
invoice_no = models.PositiveIntegerField(unique=True)
due_date = models.DateField(blank=True,null=True)
address = models.TextField()
total_amount = models.PositiveIntegerField(null=True,blank=True)
description = models.TextField(null=True,blank=True)
transiction_type = models.CharField(max_length=50,blank=True)
author = models.CharField(max_length=30)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.address
Understanding the issue with jQuery date picker:
{# Date Picker #}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( ".vdate" ).datepicker({
dateFormat: "dd-mm-yy"
});
} );
</script>
I need to identify the mistake causing the validation error.