Skip to content

Commit

Permalink
Provide type arguments to field base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mthuurne committed Jun 12, 2024
1 parent f2028aa commit 8fe4407
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions model_utils/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@

if TYPE_CHECKING:
from collections.abc import Callable, Iterable
from datetime import datetime
from datetime import date, datetime

DateTimeFieldBase = models.DateTimeField[str | datetime | date, datetime]
else:
DateTimeFieldBase = models.DateTimeField

DEFAULT_CHOICES_NAME = 'STATUS'


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


class MonitorField(models.DateTimeField):
class MonitorField(DateTimeFieldBase):
"""
A DateTimeField that monitors another field on the same model and
sets itself to the current date/time whenever the monitored field
Expand Down

0 comments on commit 8fe4407

Please sign in to comment.