Reputation: 729
I'm going through an example where a Model has a DateTimeField
defined upon it. When trying to create a filtered QuerySet with a date
lookup, the following error is returned. I'm confused as to why this error is being raised. It makes it sound like a function that I wrote is causing the error (which is not the case), but perhaps I'm reading that incorrectly.
django.db.utils.OperationalError: user-defined function raised exception
>>> a = Employee.objects.create(
alias="User", age=0, hired=datetime(2020, 6, 12), experience=0
)
>>> result = Employee.objects.filter(hired__date__gt=datetime(2019, 1, 1))
from django.db import models
class Employee(models.Model):
alias = models.CharField(unique=True, max_length=11)
age = models.IntegerField()
hired = models.DateTimeField()
experience = models.IntegerField()
def __str__(self):
return self.alias
Upvotes: 0
Views: 150
Reputation: 1490
It should be,
result = Employee.objects.filter(hired__date__gte=datetime.date(2019, 1, 1))
Upvotes: 1