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 9198081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:12:19+00:00 2026-06-17T22:12:19+00:00

I have the following: models.py class Person(models.Model): full_name = models.CharField(…) address = models.CharField(…) views.py

  • 0

I have the following:

models.py

class Person(models.Model):
    full_name = models.CharField(...)
    address = models.CharField(...)

views.py

def all_persons(request):
    persons = Person.objects.all()
    return render(
        request, 
        'my_template.html', 
        {
            'persons':persons
        }
    )

my_template.html

<table class="table table-striped">
    <thead> 
    <tr> 
    <th>Person's Fullname</th>
    </tr>
    </thead> 
    <tbody>
    {% for person in persons %}
        <td>{{ person.full_name }}</td>
        <td>{{ person.address }}</td>

Ok, so the code as it is will display an unordered list of persons in the template, of course I can manage to order by Person’s name or address, I want to give the user the possibility to order by any field, I want to accomplish this with a button on each column of the table in the template. For example a button on top of full_name and a button on top of address, if any of those is pressed, then the list should be ordered depending on the pressed button.

Thank you very much for reading, hope you can help me.

Edit: I use Twitter Boostrap 2, so tablesorter and DataTables JS wont work.

  • 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-17T22:12:20+00:00Added an answer on June 17, 2026 at 10:12 pm

    Check out this JS plugin for HTML tables: Datatables. Comes with sorting, filtering, pagination, lots of plugins. Easy to get started, but you might consider it a bit bloated.

    Another way is to have the view take an extra argument (an integer representing a field, for example), sort the queryset by this field and render the template.

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

Sidebar

Related Questions

I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
Say I have the following model: class Person(models.Model): street_address = models.CharField(max_length=50, blank=True) suburb =
I have the following models (I left out def __unicode__(...) for clarity): class Person(models.Model):
If I have the following Model: class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)
Imagine I have the following model: class Person(models.Model): ...other stuff... optional_first_name= models.CharField(max_length=50, blank=True) How
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
So I have the following model: public class Person { public String FirstName {
I have the following model, view and controller. Model public class Person { public

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.