mirror of
https://github.com/Hopiu/django-model-utils.git
synced 2026-03-16 20:00:23 +00:00
Provide type arguments to field base classes
This commit is contained in:
parent
00937608fa
commit
5fc37eb4b4
1 changed files with 7 additions and 3 deletions
|
|
@ -12,12 +12,16 @@ from django.utils.timezone import now
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Callable, Iterable
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
|
|
||||||
|
DateTimeFieldBase = models.DateTimeField[Union[str, datetime, date], datetime]
|
||||||
|
else:
|
||||||
|
DateTimeFieldBase = models.DateTimeField
|
||||||
|
|
||||||
DEFAULT_CHOICES_NAME = 'STATUS'
|
DEFAULT_CHOICES_NAME = 'STATUS'
|
||||||
|
|
||||||
|
|
||||||
class AutoCreatedField(models.DateTimeField):
|
class AutoCreatedField(DateTimeFieldBase):
|
||||||
"""
|
"""
|
||||||
A DateTimeField that automatically populates itself at
|
A DateTimeField that automatically populates itself at
|
||||||
object creation.
|
object creation.
|
||||||
|
|
@ -111,7 +115,7 @@ class StatusField(models.CharField):
|
||||||
return name, path, args, kwargs
|
return name, path, args, kwargs
|
||||||
|
|
||||||
|
|
||||||
class MonitorField(models.DateTimeField):
|
class MonitorField(DateTimeFieldBase):
|
||||||
"""
|
"""
|
||||||
A DateTimeField that monitors another field on the same model and
|
A DateTimeField that monitors another field on the same model and
|
||||||
sets itself to the current date/time whenever the monitored field
|
sets itself to the current date/time whenever the monitored field
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue