mercredi 29 avril 2015

django: loading content to main view

I have written a small django app to manage museum artwork. The app has a map and one view that reloads content every time the user clicks a marker on the map.

Currently, the content of this view is split into several templates that are received as html after a "load" request is sent. I then update the div in the main view with the received html:

// museumPk is the django primary key corresponding to the map marker
$.get("tabs/artists", { "id" : museumPk }, function (html) {
    insert("#artists", html);
});

$.get("tabs/nearby", { "id" : museumPk }, function (html) {
    insert("#nearby", html)
});

$.get("museum", { "id" : museumPk }, function (html) {
    insert("#museum-description", html)
});

For completeness, here's the "museum" template I send after the request is made; this will get inserted in the #museum div:

<a class="thumbnail pull-left" href="{{ museum.åwebsite }}">
    <img src="{{ museum.image.image.url }}" class="media-object" style="width:50px; height:50px;">
</a>
<div class="media-body">
    <h4 class="media-heading">{{ museum.title }}</h4>
    <p>{{ museum.description }}</p>
</div>

My question: is this really the correct way I should be handling things? Is there a less jquery intensive solution? Is there any way to avoid these multiple calls to insert html into my main view, and instead package things in one request?

Aucun commentaire:

Enregistrer un commentaire