-
Hey, I'm new to Django Unicorn. it's amazing! class Task(models.Model):
text = models.TextField()
def __str__(self):
return self.text class TodoView(UnicornView):
task: str = ''
tasks: QuerySet[Task] = Task.objects.none()
def mount(self):
self.tasks = Task.objects.all()
def add(self):
Task.objects.create(text=self.task)
self.task = '' If I add self.mount() to TodoView add() method the component will be updated but is this action OK? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks! I hope it's been easy to work with so far. :) Yep, that's a fine way to handle it. class TodoView(UnicornView):
task: str = ''
tasks: QuerySet[Task] = Task.objects.none()
def mount(self):
self.get_all_tasks()
def get_all_tasks(self):
self.tasks = Task.objects.all()
def add(self):
Task.objects.create(text=self.task)
self.task = ''
self.get_all_tasks() A more elaborate example is in the sample project (which attempts to exercise most of the functionality in |
Beta Was this translation helpful? Give feedback.
Thanks! I hope it's been easy to work with so far. :)
Yep, that's a fine way to handle it.
mount
is just another function as far as the actual Python is concerned so it can be called whenever you need to. The other thing I've done in the past to be very explicit about what is happening would be something like:A more elaborate example is in the sample project (…