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

  • Home
  • SEARCH
  • 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 9204161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:38:34+00:00 2026-06-17T23:38:34+00:00

I have a model: models.py class Person(models.Model): name = models.CharField(…) def __unicode__(self): return u’%s’

  • 0

I have a model:

models.py

class Person(models.Model):
    name = models.CharField(...)

    def __unicode__(self):
        return u'%s' % self.name

class Entity(models.Model):
    client = models.ForeignKey(Person)

In my view I just want to obtain all the Entities and order them by the name of the client:

views.py

def all_entities(request):
    entities = Entity.objects.all().order_by('client')
    return render(request, 'template.html', {'entities': entities})

And so my template just prints all the entities.

template.html

<html>
{% for entity on entities %}
 {{ entity.client }}}
{% endfor %}
</html>

Happens is that in my development PC all works pretty good, I get a list of ordered client names, what I can’t understand is that on my production server on webfaction.com the result is not ordered alphabetically as in my local environment.

I testes it on the shell too, results are the same, somehow order_by(‘client’) is returning an alphabetically sorted list on my PC but not alphabetically ordered on production.

Notes: Both environments have Postgres and use the same backend.

Thanks

  • 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-17T23:38:36+00:00Added an answer on June 17, 2026 at 11:38 pm

    Well, I’m not going to try to figure out why it appears to work for you, but I can’t help but notice that the ORM wouldn’t know which field to order by given a direct order to order by client.

    It’s probably just sorting by PK.

    entities = Entity.objects.all().order_by('client__name') 
    #                                               ^^^^^^ specify sort field
    #                    I am addicted to carets
    
    • 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 =
I have 2 models: class Person( models.Model ): username = models.CharField name = models.CharField(
Hay, I have a Model which looks like this class Person(models.Model): name = models.CharField(blank=False,
I have this models in Django class Country(models.Model): name = models.CharField(max_length=80) class Person(models.Model): first_name
Say I have a Django class something like this: class Person(models.Model): name = models.CharField(max_length=50)
I have these models: class Person(models.Model): name=models.CharField(max_length=100) family=models.CharField(max_length=100) class MailContact(models.Model): person=models.ForeignKey(Person) email=models.CharField(max_length=100) #some fields
I have models as follows: class Place(models.Model): name = models.CharField(max_length=300) class Person(models.Model): name =
Say I have the good old person/group/membership relationship class Person(models.Model): name = models.CharField(max_length=128) def
I have the following models (I left out def __unicode__(...) for clarity): class Person(models.Model):
If I have 2 interlinked models: class Person(models.Model) name = models.CharField() class Project(models.Model): person

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.