Skip to content

how make AJAX call work when using model #355

Answered by adamghill
ilia4bit asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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 (…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ilia4bit
Comment options

Answer selected by ilia4bit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants