Skip to content

Commit e92f551

Browse files
committed
Add model typehint to example app.
1 parent 3cf8d32 commit e92f551

File tree

2 files changed

+67
-62
lines changed

2 files changed

+67
-62
lines changed

example/unicorn/components/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ def available_flavors(self):
3131
def available_tastes(self):
3232
return Taste.objects.all()
3333

34+
def model_typehint(self, flavor: Flavor):
35+
print(flavor)
36+
3437
class Meta:
3538
javascript_exclude = ("flavor.taste_set",)
Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,79 @@
11
<div>
2-
<style>
3-
.dirty {
4-
border: red 1px solid !important;
5-
}
6-
</style>
2+
<style>
3+
.dirty {
4+
border: red 1px solid !important;
5+
}
6+
7+
</style>
8+
9+
<div>
10+
<h3>Using unicorn:model with Django models</h3>
711

812
<div>
9-
<h3>Using unicorn:model with Django models</h3>
13+
<div>
14+
<label>Name</label>
15+
<input type="text" unicorn:model="flavor.name"></input>
16+
</div>
1017

11-
<div>
12-
<div>
13-
<label>Name</label>
14-
<input type="text" unicorn:model="flavor.name"></input>
15-
</div>
16-
17-
<div>
18-
<label>Label</label>
19-
<input type="text" unicorn:model="flavor.label"></input>
20-
</div>
18+
<div>
19+
<label>Label</label>
20+
<input type="text" unicorn:model="flavor.label"></input>
21+
</div>
2122

22-
<button unicorn:click="save_flavor">save_flavor</button>
23+
<button unicorn:click="save_flavor">save_flavor</button>
2324

24-
{% for flavor in flavors %}
25-
<div>
26-
<h4>{{ flavor.pk }}</h4>
27-
<label>Name</label>
28-
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.name" u:dirty.class="dirty"></input>
29-
{{ flavor.name }}
30-
<br />
25+
{% for flavor in flavors %}
26+
<div>
27+
<h4>{{ flavor.pk }}</h4>
28+
<label>Name</label>
29+
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.name" u:dirty.class="dirty"></input>
30+
{{ flavor.name }}
31+
<br />
3132

32-
<label>Label</label>
33-
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.label" u:dirty.class="dirty"></input>
34-
{{ flavor.label }}
35-
<br />
33+
<label>Label</label>
34+
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.label" u:dirty.class="dirty"></input>
35+
{{ flavor.label }}
36+
<br />
3637

37-
<label>Float</label>
38-
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.float_value"></input>
39-
{{ flavor.float_value }}
40-
<br />
38+
<label>Float</label>
39+
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.float_value"></input>
40+
{{ flavor.float_value }}
41+
<br />
4142

42-
<label>Decimal value</label>
43-
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.decimal_value"></input>
44-
{{ flavor.decimal_value }}
45-
<br />
43+
<label>Decimal value</label>
44+
<input type="text" unicorn:model="flavors.{{ forloop.counter0 }}.decimal_value"></input>
45+
{{ flavor.decimal_value }}
46+
<br />
4647

47-
<label>Parent</label>
48-
<select unicorn:model="flavors.{{ forloop.counter0 }}.parent">
49-
<option value="">n/a</option>
50-
{% for available_flavor in available_flavors %}
51-
<option value="{{ available_flavor.pk }}">{{ available_flavor.name }}</option>
52-
{% endfor %}
53-
</select>
54-
{{ flavor.parent.name }}
55-
<br />
48+
<label>Parent</label>
49+
<select unicorn:model="flavors.{{ forloop.counter0 }}.parent">
50+
<option value="">n/a</option>
51+
{% for available_flavor in available_flavors %}
52+
<option value="{{ available_flavor.pk }}">{{ available_flavor.name }}</option>
53+
{% endfor %}
54+
</select>
55+
{{ flavor.parent.name }}
56+
<br />
5657

57-
<label>Taste</label>
58-
<select unicorn:model="flavors.{{ forloop.counter0 }}.taste_set" multiple>
59-
{% for available_taste in available_tastes %}
60-
<option value="{{ available_taste.pk }}">{{ available_taste.name }}</option>
61-
{% endfor %}
62-
</select>
58+
<label>Taste</label>
59+
<select unicorn:model="flavors.{{ forloop.counter0 }}.taste_set" multiple>
60+
{% for available_taste in available_tastes %}
61+
<option value="{{ available_taste.pk }}">{{ available_taste.name }}</option>
62+
{% endfor %}
63+
</select>
6364

64-
<ul>
65-
{% for taste in flavor.taste_set.all %}
66-
<li>{{ taste.name }}</li>
67-
{% endfor %}
68-
</ul>
69-
<br />
65+
<ul>
66+
{% for taste in flavor.taste_set.all %}
67+
<li>{{ taste.name }}</li>
68+
{% endfor %}
69+
</ul>
70+
<br />
7071

71-
<button unicorn:click="save({{ forloop.counter0 }})">save(flavor_idx)</button>
72-
<button unicorn:click="delete({{ flavor.pk }})">delete(flavor.pk)</button>
73-
</div>
74-
{% endfor %}
75-
</div>
72+
<button unicorn:click="save({{ forloop.counter0 }})">save(flavor_idx)</button>
73+
<button unicorn:click="delete({{ flavor.pk }})">delete(flavor.pk)</button>
74+
<button u:click="model_typehint({{ flavor.pk }})">model_typehint(flavor.pk)</button>
75+
</div>
76+
{% endfor %}
7677
</div>
78+
</div>
7779
</div>

0 commit comments

Comments
 (0)