Skip to content

Commit 9836398

Browse files
committed
Add datetime with type hint example to objects.
1 parent c7b5665 commit 9836398

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

example/unicorn/components/objects.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timedelta
22
from decimal import Decimal as D
33
from enum import Enum
44
from typing import Optional
@@ -42,6 +42,7 @@ class ObjectsView(UnicornView):
4242
book = Book(title="The Sandman")
4343
books = Book.objects.all()
4444
date_example = now()
45+
date_example_with_typehint: datetime = now()
4546
float_example: float = 1.1
4647
decimal_example = D("1.1")
4748
int_example = 4
@@ -55,6 +56,11 @@ def check_date(self, dt: datetime):
5556

5657
self.date_example = dt
5758

59+
def add_hour(self):
60+
self.date_example_with_typehint = self.date_example_with_typehint + timedelta(
61+
hours=1
62+
)
63+
5864
def set_dictionary(self, val):
5965
self.dictionary = val
6066

example/unicorn/templates/unicorn/objects.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
<button u:click='check_date("{{ date_example|date:'c' }}")'>check_date (c)</button>
4545
<button u:click='check_date({{ date_example|date:'U' }})'>check_date (U)</button>
4646
</div>
47+
48+
<div>
49+
{{ date_example_with_typehint }}
50+
</div>
51+
<div>
52+
<button u:click='add_hour()'>add_hour()</button>
53+
</div>
4754
</div>
4855

4956
<div>

0 commit comments

Comments
 (0)