1
0
Fork 0

Reduce SQL queries in user page

Signed-off-by: Alfredos-Panagiotis Damkalis <fredy@fredy.gr>
merge-requests/795/head 1.16
Alfredos-Panagiotis Damkalis 2019-11-28 16:46:40 +02:00
parent be174ad4dd
commit 460f6ea66d
2 changed files with 5 additions and 3 deletions

View File

@ -42,7 +42,7 @@
<th>Antennas</th>
</thead>
<tbody>
{% for station in stations.all %}
{% for station in stations %}
<tr class="clickable-row" data-href="{% url 'base:station_view' station_id=station.id %}">
<td>
<a href="{% url 'base:station_view' station_id=station.id %}">
@ -145,7 +145,7 @@
<th>Station</th>
</thead>
<tbody>
{% for observation in observations.all %}
{% for observation in observations %}
<tr class="clickable-row" data-href="{% url 'base:observation_view' observation_id=observation.id %}">
<td>
<a href="{% url 'base:observation_view' observation_id=observation.id %}">

View File

@ -37,7 +37,9 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
def view_user(request, username):
"""View for user page."""
user = get_object_or_404(User, username=username)
observations = Observation.objects.filter(author=user)[0:10]
observations = Observation.objects.filter(
author=user
)[0:10].prefetch_related('satellite', 'ground_station')
stations = Station.objects.filter(owner=user).annotate(total_obs=Count('observations'))
token = ''