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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:56:07+00:00 2026-06-15T17:56:07+00:00

I am using Django. I’m working on a view function to try to show

  • 0

I am using Django. I’m working on a view function to try to show a list of budget transactions from my database along with other info like date, category, and a description. (Transaction is my model, so they’re Transaction objects.) The transaction amounts are stored in integer format in the db (following some suggestions I saw here), as currency was supposedly easier to handle converting to int and back to decimal. (Now I’m not so sure.) I’m trying to convert back to decimal before sending the set of objects to a template for display. I can’t figure out how to pull the amount out of each Transaction object, convert it to decimal, and get it back into the objects. I’m trying to do something like this:

object_list = Transaction.objects.all()

for obj in range(0,object_list.count()):
    object_list[obj].dec_amount = Decimal(object_list[obj].amount/100).quantize(Decimal('0.01'))

And the template, very simple for now:

{% for item in object_list %}

<tr>
<td>{{ item.dec_amount }}</td>
<td>{{ item.category }}</td>
<td>{{ item.date }}</td>

</tr>

{% endfor %}

I’m basically trying to create a new dec_amount attribute in each object, but I don’t know if that works. The dec_amount is not available in my template. I also just think there must be a more elegant way to iterate over the objects to update their amount or create a new attribute with the decimal value. Or, maybe there’s a more efficient way with pulling the QuerySet, but I don’t see how I can easily keep the rows together between two queries that way. How can I use a loop to modify one attribute in every object of a QuerySet?

Thanks for any help. I gotta say, I’m getting frustrated — coming from PHP, the whole Decimal thing seems more complicated.

EDIT: Tried to improve my terminology a bit.

  • 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-15T17:56:08+00:00Added an answer on June 15, 2026 at 5:56 pm

    If you just need to access the decimal value in templates, you could consider a property like this:

    class Transaction(models.Model):
        @property
        def dec_amount(self):
            return Decimal(self.amount / 100).quantize(Decimal('0.01'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using django-social-auth to grab user data from facebook, it is returning a list of
Using Django 1.3 with PostgreSQL 9.0, I have a multi-step object creation function/view, where:
Using Django 1.1, I am trying to select the maximum value from a varchar
Am using django social-auth authentication for my app.After login to facebook or twitter from
I using Django tagging project. That is was very stable project. Working on django
I using Django and a generic view django.views.generic.create_update.create_object I have a model form wich
(Using django as an example; the ForeignKey is implicit in the example) >>> from
Using django, I'm trying to get a QuerySet of FK relationships from another QuerySet.
using django 1.4 im getting a 403 error when i try to do a
By using django ORM: How to match the result in database is NOT null?

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.