Note that there are some explanatory texts on larger screens.

plurals
  1. POa custom pagination problem in template in django 1.3
    primarykey
    data
    text
    <p>I'm making a gallery where i have two models. like below</p> <pre><code>class Gallery(models.Model): name = models.CharField(max_length=200) pub_date = models.DateTimeField('date published', auto_now_add=True) slug_name = models.CharField(max_length=200) def __unicode__(self): return self.name class Image(models.Model): gallery = models.ForeignKey(Gallery) image = models.ImageField(upload_to='gallery/%Y/%m/%d') caption = models.TextField(blank=True) up_date = models.DateTimeField(auto_now_add=True) def __unicode__(self): return self.caption </code></pre> <p>Now I have a view which will serve a single image page. I'm getting the images like this</p> <pre><code>def image_page(request, slug_name, image_id): image = Image.objects.get(pk = image_id) all = Gallery.objects.get(slug_name = slug_name).image_set.all() return render_to_response('gallery/image_page.html', { 'image': image, 'all': all, }, context_instance = RequestContext(request)) </code></pre> <p>By "image" I'm getting that single image. by "all" I'm getting all the images which Probably need in the view for displaying pagination. Pagination means only a next and previous button.</p> <p>Now if this single page is first page previous link should not show similarly if last page next button should not show. Other then that the both link should display. </p> <p>My question is how to do it in template? I tried using for loop not working, also another question how to link to next/previous image my urls look for /gallery/slug_name/image_id.html [note: my image id isn't growing gradually like 1,2, 3, example I have 4 image in a gallery which ids are 4, 6, 7, 8]</p> <p>BTW I tried @murgatroid99 way. It works great! But actually I then have to use url like this </p> <pre><code>http://localhost:8000/gallery/fourth-gallery/hello?image=2 </code></pre> <p>What I want is to use pagination and url like</p> <pre><code>http://localhost:8000/gallery/1, http://localhost:8000/gallery/2, http://localhost:8000/gallery/3 Etc </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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