Earlier quoted context omitted.
if self._midnight(today) returns a datetime object, than: self.filter(end__gt=self._midnight(today)) will evaluate to: self.filter(end__gt= ) While self.filter(Field.end > self._midnight(today)) will evaluate to: self.filter( )
Not if you do the magic with getattr and comparison overrides. You actually need to do it on the metaclass because the Field as I wrote it isn't an instance but this works: from datetime import datetime class Filter(): def __init__(self, name): self.name = name def __gt__(self, value): return { "field": self.name, "operator": ">", "value": value } class FieldMeta(type): def __getattr__(cls, name): return Filter(name)…
def __gt__(self, value):
return Q(**{ f"{self.name}__gt": value })
and your original code should work as-is without the need for _() self.filter(Field.end > self._midnight(today))
https://docs.djangoproject.com/en/6.0/topics/db/queries/#com...