'Why django-unicorn doesnt update hmtl-collection?
There is django-unicorn 0.44.0's component configuration.
refresh.py
from django.db import connection
from django_unicorn.components import UnicornView
from datamarket.models import Clients
class RefreshView(UnicornView):
clients = None
count = None
def get_client(self):
self.count = Clients.objects.all().count()
self.clients = Clients.objects.all().order_by("surname")[:10]
def az(self):
self.clients = Clients.objects.all().order_by("surname")[:10]
def za(self):
self.clients = Clients.objects.all().order_by("-surname")[:10]
def mount(self):
self.clients = Clients.objects.all().order_by("surname")[:10]
self.count = Clients.objects.all().count()
refresh.html
<div>
<button class="btn" unicorn:click="get_client()">Update</button>
<button class="btn" unicorn:click="az()">A-Z</button>
<button class="btn" unicorn:click="za()">Z-A</button>
<p> Total {{ count }} records</p>
</div>
<table>
<thead>
<th>Surname</th>
<th>Name</th>
<th>Age</th>
</thead>
<tbody>
{% for c in clients %}
<tr>
<td>{{ c.surname }}</td>
<td>{{ c.name }} </td>
<td>{{ c.age }}</td>
</tr>
{% empty %}
<tr>
<td colspan="3">No found</td>
</tr>
{% endfor %}
</tbody>
</table>
The mount() function doing well when I refresh page, it changes clients value in html. Also count value updating well too when I call get_clients() by button.
But it doesnt change client collection in table when I call get_clients(), az(), za() by button. Why?
It's worked literally week ago and now I dont get any errors.
Solution 1:[1]
The solve is that refresh.html need one general <div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Englio |
