I have this model
class messages(models.Model):
status_choices = (
(u'read',u'read'),
(u'unread',u'unread')
)
user = models.ForeignKey(User)
message = models.TextField()
status = models.CharField(max_length=6,choices=status_choices,default='unread')
sender = models.ForeignKey(User,related_name="sender")
Now I want to fetch only first 10 messages that belong “user1”,on the second request next 10 messages and so on.How can I do that?
Django provides this functionality already with a
Paginatorobject. In your URL you’ll need apageparameter that says on which page you are and in your view you need to construct aPaginatorobject. You need to specify the number of objects on a page (in your case 10) and thePaginatorwill do the rest.For example, the following code will print all instances that are displayed on page 3:
The documentation gives examples on how to implement your views and how to pass the list of objects to your template.