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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:48:03+00:00 2026-06-02T08:48:03+00:00

With this simple model class Publisher(models.Model): name = models.CharField(max_length = 40) website = models.URLField()

  • 0

With this simple model

class Publisher(models.Model):
    name = models.CharField(max_length = 40)
    website = models.URLField()

    def __unicode__(self):
        return self.name

and a model form

class PublisherForm(ModelForm):

    class Meta:
        model = Publisher

Updated Model

class PublisherForm(ModelForm):
    error_css_class = "error"   #class is applied if the field throws an error.
    required_css_class = "required" #outputs the cell with the class if the field is required

    def __init__(self, *args, **kwargs):
        super(PublisherForm, self).__init__(*args, **kwargs)
        self.fields.keyOrder = ['name', 'website']

    class Meta:
        model = Publisher

self.fields.keyOrder has no effect on the order of the error messages. It only changes the order of the fields.

The order of the fields generated by form.as_table is in the order of them being declared in the model

I ran this code in the shell

from booksapp import models
>>> f = models.PublisherForm({})
>>> f.is_valid()
False
>>> f.as_table()
u'<tr class="required error"><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_name" type="text" name="name" maxlength="40" /></td></tr>\n<tr class="required error"><th><label for="id_website">Website:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input id="id_website" type="text" name="website" maxlength="200" /></td></tr>'
>>> f.errors
{'website': [u'This field is required.'], 'name': [u'This field is required.']}
>>> 

Here the order of the html is correct according to the model but the order of the errors is not. I think the name should come first.

This will be an issue if I need to output the errors above the form and not inline.

How to get the order of the error messages to be the same as the fields in the model? What do you do if you would have to display the error messages at the top?

  • 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-02T08:48:07+00:00Added an answer on June 2, 2026 at 8:48 am

    You need to go through the form’s data to get the field order, and then you access the appropriate elements of the error dictionary.

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

Sidebar

Related Questions

I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have this simple Blog model: class Blog(models.Model): title = models.CharField(_('title'), max_length=60, blank=True, null=True)
I have this simple Post model: class Post(models.Model): title = models.CharField(_('title'), max_length=60, blank=True, null=True)
I've created a simple model class Person(models.Model): name = models.CharField(max_length=25) surname = models.CharField(max_length=25) birth_date
Assume I have such simple model: class Foo(models.Model): name = models.CharField(max_length=25) b_date = models.DateField()
I have this simple model: class Tag(models.Model): title = models.SlugField() created = models.datetime def
Consider the models: class Author(models.Model): name = models.CharField(max_length=200, unique=True) class Book(models.Model): pub_date = models.DateTimeField()
This is my model: class News(models.Model): title = models.CharField(max_length=250) text = models.TextField() pub_date =
Hi Suppose I have a simple model class like this: class TestModel(models.Model): testkey =
I need some help with this one.... I have this simple model: public 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.