-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert strings values to appropriate types
- Loading branch information
1 parent
ba99a55
commit 4150cdc
Showing
3 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django_unixdatetimefield import UnixDateTimeField as BaseUnixDateTimeField | ||
import datetime | ||
|
||
|
||
class UnixDateTimeField(BaseUnixDateTimeField): | ||
def to_python(self, val): | ||
if val is None or isinstance(val, datetime.datetime): | ||
return val | ||
if isinstance(val, datetime.date): | ||
return datetime.datetime(val.year, val.month, val.day) | ||
else: | ||
try: | ||
return datetime.datetime.fromtimestamp(float(val)) | ||
except OSError: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters