Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:27:18+00:00 2026-06-07T12:27:18+00:00

I have this model class messages(models.Model): status_choices = ( (u’read’,u’read’), (u’unread’,u’unread’) ) user =

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:27:20+00:00Added an answer on June 7, 2026 at 12:27 pm

    Django provides this functionality already with a Paginator object. In your URL you’ll need a page parameter that says on which page you are and in your view you need to construct a Paginator object. You need to specify the number of objects on a page (in your case 10) and the Paginator will do the rest.

    For example, the following code will print all instances that are displayed on page 3:

    from django.core.paginator import Paginator
    
    objects = messages.objects.all()
    p = Paginator(objects, 10)
    page3 = p.page(3)
    print page3.object_list
    

    The documentation gives examples on how to implement your views and how to pass the list of objects to your template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
I have this Project model: class Project < ActiveRecord::Base validates :status, :inclusion => {
I have this model in django: class JournalsGeneral(models.Model): jid = models.AutoField(primary_key=True) code = models.CharField(Code,
I have this setup in my models: class Author(models.Model): name = models.CharField(max_length=100) class Topic(models.Model):
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
I have this Pin Model: class Pin < ActiveRecord::Base belongs_to :user belongs_to :image accepts_nested_attributes_for
I have a class Similar to this public class Model { public TimeSpan Time1
Let's say I have a model class called Project, but instead of this: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.