I am Building a BlogApp and I am stuck on an Error. I tried many times and tried many answers but nothing solved my error.
def validate_date(date_added):
if date_added < timezone.now().date():
raise ValidationError("Date cannot be in the past")
class BlogPost(models.Model):
post_owner = models.ForeignKey(User,default='',null=True,on_delete = models.CASCADE)
post_title = models.CharField(max_length=500,default='')
date_added = models.DateTimeField(null=True,default=timezone.now,validators=[validate_date])
The Work of this Function
Work of this function is to prevent past date as a input.
The Problem
Whenever i try to make a new blogpost and try to add the past date then it is keep showing me :-
can't compare datetime.datetime to datetime.date
What have i tried
I tried many answers like This but nothing worked for me.
I don't know what is wrong in this code.
Any help would be appreciated.
Thank You in Advance