Hi there,
thanks a lot for creating for us a new magic!
I am trying to get through the docs and being stuck on DbModel part: https://www.django-unicorn.com/docs/django-models/#dbmodel
I've followed the examples, here is what I have:
model:
class Todo(models.Model):
description = models.CharField(max_length=50)
is_completed = models.BooleanField(default=False, blank=True)
due_date = models.DateField(null=True, blank=True)
unicorn view ('add_todo_test.py')
from django_unicorn.components import UnicornView
from django_unicorn.db import DbModel
from todos.models import Todo
class AddTodoTestView(UnicornView):
class Meta:
db_models = [DbModel("todo", Todo)]
def save(self):
print("A new book will be created automatically")
pass
and component ('add-todo-test.html')
<div>
<div>
<input unicorn:db="todo" unicorn:field.defer="description" type="text" id="description" />
{{ todo.description }}
</div>
<div>
<input unicorn:db="todo" unicorn:field.defer="due_date" type="text" id="due_date" />
{{ todo.due_date }}
</div>
<button unicorn:click="save">Save</button>
</div>
Component is rendered, but it doesn't work and I get the following error message in browser's dev console:
component.js:404 Uncaught Error: Setting a field value requires a model to be set
at component.js:404
at Array.forEach (<anonymous>)
at Component.setDbModelValues (component.js:398)
at Module.componentInit (unicorn.js:35)
at (index):92
(anonymous) @ component.js:404
setDbModelValues @ component.js:398
componentInit @ unicorn.js:35
(anonymous) @ (index):92
I simply cannot understand what am I doing wrong :)
P.S. Don't know if that plays any role, but in PyCharm I get the following warning:
bug