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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:06:42+00:00 2026-06-17T19:06:42+00:00

I want to right align numeric fields in the admin interface of my Django

  • 0

I want to right align numeric fields in the admin interface of my Django app. For “normal” editable fields this works ok by overriding formfield_for_dbfield(self, db_field, **kwargs): for the ModelAdmin class:

def formfield_for_dbfield(self, db_field, **kwargs):
    field = super(MyModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
    if db_field.name in ("total_amount", "total_discount_amount"):
        field.widget.attrs['style'] = 'text-align:right;'
    return field

When a field is defined as a read-only field, it by passes this method and gets rendered in a different way (apparently just as a css styled paragraph tag).

Is there a way to right align a read-only field? I found this question on SO but its problem is a different one from mine, I think…

  • 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-17T19:06:43+00:00Added an answer on June 17, 2026 at 7:06 pm

    Why not just use css? Define a an /admin/base.html template in which you load a custom css that specifies:

    input[readonly="readonly"]{
        text-align: right
    }
    

    If you need to restrict the styiling of certain readonly fields you could still use css by doing something like:

    #my-app fieldset input[readonly="readonly"]{
        text-align: right
    }
    

    or even specific fields:

    #id_total, #id_average, #id_my_readonly_field{
        text-align: right
    }
    

    Addendum

    I see you are using Grappelli, in that case you could do:

    .grp-readonly{
        float: right;
    }
    

    If you need to style only certain readonly paragraphs and not all of them you could still prefix the CSS rule with the css class of the parent element, usually the class is named after the field name, so if you have a file called “total” it would be:

    .total .grp-readonly{
        float: right;
    }
    

    I think writing a custom filter for a presentation issue is a mantainance overkill that you might regret in the future, are you sure that’s the best way to do it?

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

Sidebar

Related Questions

I want to right-align numeric values in a CellTable. I already tried looking for
As gathered from Why align="center" not overriding on {text-align:right;} this article, CSS should take
I want to change this CSS text-align. it's right but I want it to
I want to right-align an inline element to the right of a div .
I want to make a right click menu for my winforms app. It will
I have a label that I want to right align to be able to
I have an ASP.NET control. I want to align the textbox to the right
I have these two button divs which I want to align right under each
I'm having trouble finding the right solution for this fully fluid layout. I want
Can you easily right-align just one column in a GridView? I have this <asp:GridView

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.