Skip to content

Commit bc53e06

Browse files
committed
Example fix for issue 168.
1 parent 3a8d7ef commit bc53e06

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed

example/todos/__init__.py

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.1.7 on 2021-03-13 02:54
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Todo',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('description', models.CharField(max_length=50)),
19+
('is_completed', models.BooleanField(blank=True, default=False)),
20+
('due_date', models.DateField(blank=True, null=True)),
21+
],
22+
),
23+
]

example/todos/migrations/__init__.py

Whitespace-only changes.

example/todos/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.db import models
2+
3+
4+
class Todo(models.Model):
5+
description = models.CharField(max_length=50)
6+
is_completed = models.BooleanField(default=False, blank=True)
7+
due_date = models.DateField(null=True, blank=True)
8+
9+
class Meta:
10+
app_label = "todos"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django_unicorn.components import UnicornView
2+
from django_unicorn.db import DbModel
3+
from example.todos.models import Todo
4+
5+
6+
class AddTodoTestView(UnicornView):
7+
class Meta:
8+
db_models = [DbModel("todo", Todo)]
9+
10+
def save(self):
11+
print("A new book will be created automatically")
12+
pass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div unicorn:db="todo">
2+
<div>
3+
<input unicorn:field.defer="description" type="text" id="description" />
4+
{{ todo.description }}
5+
</div>
6+
<div>
7+
<input unicorn:field.defer="due_date" type="text" id="due_date" />
8+
{{ todo.due_date }}
9+
</div>
10+
<button unicorn:click="save">Save</button>
11+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "www/base.html" %}
2+
{% load static unicorn %}
3+
4+
{% block content %}
5+
6+
<h2>Issue 168 test</h2>
7+
8+
{% unicorn 'add-todo-test' %}
9+
10+
{% endblock content %}

0 commit comments

Comments
 (0)