# Pagination may yield inconsistent results with an unordered object\_list

**URL:** https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472
**Category:** Forms & APIs
**Created:** [May 1, 2022, 5:55am UTC](https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472 "2022-05-01T05:55:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Bryan-Michael-Tice](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bryan-michael-tice/32/8272_2.png) [@Bryan-Michael-Tice](https://forum.djangoproject.com/u/Bryan-Michael-Tice)
#### Post date: [May 1, 2022, 5:55am UTC](https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472/1 "2022-05-01T05:55:48Z")

</div>

Greetings!

I can display a list of pages from entry forms that create objects submitted in my app it looks as follows:

```auto
Casa object (1)
Casa object (2)
Casa object (3)
Casa object (4)
Casa object (5)
Casa object (6)
Casa object (7)
Casa object (8)
Casa object (9)
Casa object (10)
Casa object (11)
Casa object (12)
Casa object (13)
Casa object (14) 

```

My source is the pagination documentation, I am attempting to change my views to display 1 object at a time.

Method, take this:

```auto
def home(request):

    context = {
        'casa' : Casa.objects.all()
    }
    return render(request,'CMS/home.html',context)

```

and do this:

```auto
def home(request):
    
    student_list = Casa.objects.all()
    paginator = Paginator (student_list,1)

    page_number = request.GET.get('page')
    page_obj = paginator.get_page(page_number)
    context = {
        'casa' : Casa.objects.all()
    }
    return render(request,'CMS/home.html',{'page_obj':page_obj})

```

any help is appreciated kind Django brethren!

best,

Bryan

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [May 1, 2022, 11:45am UTC](https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472/2 "2022-05-01T11:45:58Z")

</div>

Take a wild guess here - what do you think that that error message is telling you?

Or, what results do you get if you put that specific phrase into the search bar on the forum? (The “magnifying glass” icon on the top right.)

---

<div class="post-metadata">

### Author: ![Bryan-Michael-Tice](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bryan-michael-tice/32/8272_2.png) [@Bryan-Michael-Tice](https://forum.djangoproject.com/u/Bryan-Michael-Tice)
#### Post date: [May 2, 2022, 12:31am UTC](https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472/3 "2022-05-02T00:31:59Z")

</div>

Ken!!

You are always so helpful! I utilized the aforementioned sherlock device found, “adding an order\_by clause on the queryset or an ordering in the Meta for that model.” (@KenWhitesell )

I’d like to sort the object list in the meta data. Where does the sort function fit properly in my views.py?

```auto
Entry.objects.order_by('model')

```

my class in views.py:

```auto
class StudentForm(ModelForm):
    class Meta:
        model = models.Casa
        fields = ['Student','Cohort','Phone_Number','Email_Address','Home_Address','City','State','Zip_Code']
    @property
    def helper(self):
        helper =FormHelper()
        helper.layout = Layout(

            HTML('<h2> Submit Entry</h2>'),
 # Field('Student'),
 # Field('Cohort'),
 # Field('Phone_Number'),
  # Field('Email_Address'),
  # Field('Home_Address'),
  # Field('City'),
  # Field('State'),
  # Field('Zip_Code'),
  # Submit('submit','Submit Entry',css_class='btn-success')           
        )
        for field in self.Meta().fields:#loop through fields instead.. 
            helper.layout.append(
                Field(field, wrapper_class='row')
            )
        helper.layout.append(Submit('submit','Submit Entry',css_class='btn-success'))
        helper.field_class = 'col-9'
        helper.label_class = 'col-3'
        return helper

```

---

<div class="post-metadata">

### Author: ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)
#### Post date: [May 2, 2022, 1:00am UTC](https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472/4 "2022-05-02T01:00:56Z")

</div>

That’s your form, not your view.

You can apply the sort to the queryset retrieving the objects being displayed.

Or, as you wrote:

> [@Bryan-Michael-Tice](#):
>
> I’d like to sort the object list in the meta data.

> [@Bryan-Michael-Tice](#):
>
> an ordering in the Meta for that model.

You set that ordering in the Meta class for the model, not the form or the view.

See [Models | Django documentation | Django](https://docs.djangoproject.com/en/4.0/topics/db/models/#meta-options-1) and [Model Meta options | Django documentation | Django](https://docs.djangoproject.com/en/4.0/ref/models/options/#model-meta-options).

---

<div class="post-metadata">

### Author: ![Bryan-Michael-Tice](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bryan-michael-tice/32/8272_2.png) [@Bryan-Michael-Tice](https://forum.djangoproject.com/u/Bryan-Michael-Tice)
#### Post date: [May 2, 2022, 4:21am UTC](https://forum.djangoproject.com/t/pagination-may-yield-inconsistent-results-with-an-unordered-object-list/13472/5 "2022-05-02T04:21:51Z")

</div>

Ken,

Thank you and noted. Set the ordering in the meta class for that model. This cleared the error, after a migration, but the data is not paginated/displayed when the url is reached. Thank you very much for your help. I will research the links above to see if I can see why (:

Have a great week!

B
