Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Limiting database hits to retrieve related models [RSS Feed]

#1 March 24, 2008 22:48:08

[EMAIL P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Limiting database hits to retrieve related models


Hi,

I am starting a simple web app that can be introduced as a collection
of Agendas (represented as Django models).
Each Agenda is composed of Appointments (at least one), and each
Appointment records 0 or more Invitees.
Basically, I would like to display the content of this Agenda on a
page, i.e list all its Appointments, and display the list of Invitees
for each Appointment.

The simplest solution I found is to retrieve my Agenda in my view, and
then rely on the template to display the subsequent elements, e.g:
{{ agenda.details }}
{% for appointment in agenda.appointment_set.all %}
{{ appointment.details }}
{% for invitee in appointment.invitee_set.all %}
{{ invitee.details}}
{% endfor %}
{% endfor %}

However, doing so, the number of queries executed increases due to the
inner loop of retrieving all invitees for each appointment of this
agenda.

Is there a better solution in terms of performance (i.e less queries
on the database), to retrieve this cascaded information? I thought
about the 'select_related' statement on my queryset, but it covers non-
null foreign keys only.

Thanks in advance for any hint.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

  • Root
  • » Django
  • » Limiting database hits to retrieve related models [RSS Feed]

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support