Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango with Ajax and jQuery
    text
    copied!<p>I would like after clicking on one of the many <code>Item</code> shown a window with his description (single item description).</p> <p>How to create this using Ajax and jQuery with Django?</p> <p>model:</p> <pre><code>class Item(models.Model): name = models.CharField(max_length=50) slug = models.SlugField() price = models.DecimalField(max_digits=5, decimal_places=2) desc = models.TextField() </code></pre> <p>views:</p> <pre><code>def item_list(request): items = Item.objects.all()[:6] return render_to_response('items.html', {'items':items}, context_instance=RequestContext(request)) def single_item(request, slug): item = Item.objects.get(slug=slug) return render_to_response('single.html', {'item':item}, context_instance=RequestContext(request)) </code></pre> <p>template:</p> <pre><code>&lt;!-- Single item description: --&gt; &lt;div id="description"&gt; &lt;img src="/site_media/images/photo.png"&gt; &lt;div id="item_description"&gt; &lt;input name="add" type="button" id="add" value="Add to Cart"&gt; &lt;p class="title"&gt;Single Item name&lt;/p&gt; &lt;p class="description"&gt;&lt;span&gt;Description:&lt;/span&gt; This is single item description &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;!-- All item: --&gt; &lt;div id="item"&gt; {% for i in items %} &lt;div class="item"&gt; &lt;img src="/{{ i.image.url }}" /&gt; &lt;p&gt; &lt;span&gt; {{ i.name }} &lt;/span&gt; &lt;span&gt; {{i.price}} &lt;/span&gt; &lt;/p&gt; &lt;/div&gt; {% endfor %} &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload