Skip to content

Commit 16555a7

Browse files
committed
Provide type arguments to field base classes
1 parent 52e243d commit 16555a7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

model_utils/fields.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212

1313
if TYPE_CHECKING:
1414
from collections.abc import Callable, Iterable
15-
from datetime import datetime
15+
from datetime import date, datetime
16+
17+
DateTimeFieldBase = models.DateTimeField[Union[str, datetime, date], datetime]
18+
else:
19+
DateTimeFieldBase = models.DateTimeField
1620

1721
DEFAULT_CHOICES_NAME = 'STATUS'
1822

1923

20-
class AutoCreatedField(models.DateTimeField):
24+
class AutoCreatedField(DateTimeFieldBase):
2125
"""
2226
A DateTimeField that automatically populates itself at
2327
object creation.
@@ -111,7 +115,7 @@ def deconstruct(self) -> tuple[str, str, Sequence[Any], dict[str, Any]]:
111115
return name, path, args, kwargs
112116

113117

114-
class MonitorField(models.DateTimeField):
118+
class MonitorField(DateTimeFieldBase):
115119
"""
116120
A DateTimeField that monitors another field on the same model and
117121
sets itself to the current date/time whenever the monitored field

0 commit comments

Comments
 (0)